Это хост.
В билде работает.
Вот сотбственно скрипт:
Синтаксис:
Используется csharp
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Player : Photon.MonoBehaviour {
GameObject cam;
Camera camera;
AudioListener al;
bool active;
Animator anim;
string[] animName = new string[5]{"idle", "left", "right", "rightgun", "leftgun"};
Vector2 oldPos = Vector2.zero;
Vector2 newPos = Vector2.zero;
int oldNumPic = 0;
int newNumPic = 0;
float newPropertyy = 0.0f;
float newPropertyx = 0.0f;
bool isSinch = false;
float offsetTime = 0f;
int animNum = 0;
float propertyX;
float propertyY;
void Start () {
if (photonView.isMine) {
gameObject.name = "Player";
cam = transform.Find("Cam").gameObject;
camera = cam.GetComponent<Camera>();
al = cam.GetComponent<AudioListener>();
active = true;
transform.position = new Vector2(Vector2.zero.x + 100.0f, Vector2.zero.y);
}else{
gameObject.name = "OtherPlayer";
cam = transform.Find("Cam").gameObject;
camera = cam.GetComponent<Camera>();
al = cam.GetComponent<AudioListener>();
active = false;
transform.position = new Vector2(Vector2.zero.x + 300.0f, Vector2.zero.y);
}
camera.enabled = active;
al.enabled = active;
cam.gameObject.SetActive(active);
anim = transform.Find("Image").GetComponent<Animator>();
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
int numPic = animNum;
stream.Serialize (ref numPic);
if (stream.isReading) {
oldNumPic = animNum;
newNumPic = numPic;
offsetTime = 0;
isSinch = true;
}
float propertyy = propertyY;
stream.Serialize (ref propertyy);
if (stream.isReading) {
newPropertyy = propertyy;
isSinch = true;
}
}
void Update(){
int i = 0;
while (i < animName.Length) {
if (photonView.isMine) {
propertyX = Input.mousePosition.x/Screen.currentResolution.width;
propertyY = Input.mousePosition.y/Screen.currentResolution.height;
if (Input.GetKey (KeyCode.A)) {
animNum = 1;
} else if (Input.GetKey (KeyCode.D)) {
animNum = 2;
} else {
if(propertyX > 0.5f){
animNum = 3;
}else{
animNum = 4;
}
}
if(animNum == 3){
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[animNum]);
anim.SetFloat("MouseProp", propertyY);
}else if(animNum == 4){
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[animNum]);
anim.SetFloat("MouseProp", propertyY);
}else{
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[animNum]);
}
} else if (isSinch) {
if(newNumPic == 3){//синхронизирую переменные animNum для смены поворота персонажа
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[newNumPic]);
anim.SetFloat("MouseProp", newPropertyy);//и propertyY дляя направления оружия
}else if(newNumPic == 4){
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[newNumPic]);
anim.SetFloat("MouseProp", newPropertyy);
}else{//это когда бегает вправо-влево
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[newNumPic]);
}
}
i++;
}
}
}
using UnityEngine.UI;
using System.Collections;
public class Player : Photon.MonoBehaviour {
GameObject cam;
Camera camera;
AudioListener al;
bool active;
Animator anim;
string[] animName = new string[5]{"idle", "left", "right", "rightgun", "leftgun"};
Vector2 oldPos = Vector2.zero;
Vector2 newPos = Vector2.zero;
int oldNumPic = 0;
int newNumPic = 0;
float newPropertyy = 0.0f;
float newPropertyx = 0.0f;
bool isSinch = false;
float offsetTime = 0f;
int animNum = 0;
float propertyX;
float propertyY;
void Start () {
if (photonView.isMine) {
gameObject.name = "Player";
cam = transform.Find("Cam").gameObject;
camera = cam.GetComponent<Camera>();
al = cam.GetComponent<AudioListener>();
active = true;
transform.position = new Vector2(Vector2.zero.x + 100.0f, Vector2.zero.y);
}else{
gameObject.name = "OtherPlayer";
cam = transform.Find("Cam").gameObject;
camera = cam.GetComponent<Camera>();
al = cam.GetComponent<AudioListener>();
active = false;
transform.position = new Vector2(Vector2.zero.x + 300.0f, Vector2.zero.y);
}
camera.enabled = active;
al.enabled = active;
cam.gameObject.SetActive(active);
anim = transform.Find("Image").GetComponent<Animator>();
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
int numPic = animNum;
stream.Serialize (ref numPic);
if (stream.isReading) {
oldNumPic = animNum;
newNumPic = numPic;
offsetTime = 0;
isSinch = true;
}
float propertyy = propertyY;
stream.Serialize (ref propertyy);
if (stream.isReading) {
newPropertyy = propertyy;
isSinch = true;
}
}
void Update(){
int i = 0;
while (i < animName.Length) {
if (photonView.isMine) {
propertyX = Input.mousePosition.x/Screen.currentResolution.width;
propertyY = Input.mousePosition.y/Screen.currentResolution.height;
if (Input.GetKey (KeyCode.A)) {
animNum = 1;
} else if (Input.GetKey (KeyCode.D)) {
animNum = 2;
} else {
if(propertyX > 0.5f){
animNum = 3;
}else{
animNum = 4;
}
}
if(animNum == 3){
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[animNum]);
anim.SetFloat("MouseProp", propertyY);
}else if(animNum == 4){
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[animNum]);
anim.SetFloat("MouseProp", propertyY);
}else{
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[animNum]);
}
} else if (isSinch) {
if(newNumPic == 3){//синхронизирую переменные animNum для смены поворота персонажа
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[newNumPic]);
anim.SetFloat("MouseProp", newPropertyy);//и propertyY дляя направления оружия
}else if(newNumPic == 4){
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[newNumPic]);
anim.SetFloat("MouseProp", newPropertyy);
}else{//это когда бегает вправо-влево
anim.runtimeAnimatorController = Resources.Load<RuntimeAnimatorController> (animName[newNumPic]);
}
}
i++;
}
}
}