void OnOtherPlayerConnected(SocketIOEvent socketIOEvent) { print("Someone else joined"); string data = socketIOEvent.data.ToString(); UserJSON userJSON = UserJSON.CreateFromJSON(data); Vector3 position = new Vector3(userJSON.position[0], userJSON.position[1], userJSON.position[2]); Quaternion rotation = Quaternion.Euler(userJSON.rotation[0], userJSON.rotation[1], userJSON.rotation[2]); GameObject o = GameObject.Find(userJSON.name) as GameObject; if (o != null) { return; } GameObject p = Instantiate(Chara_4Hero, position, rotation) as GameObject; Controller pc = p.GetComponent <Controller>(); SampleAnimation pa = p.GetComponent <SampleAnimation>(); pc.isLocalPlayer = false; pa.isLocal = false; Transform t = p.transform.Find("Healthbar Canvas"); Transform t1 = t.transform.Find("Player Name"); Text playerName = t1.GetComponent <Text>(); playerName.text = userJSON.name; p.name = userJSON.name; Health h = p.GetComponent <Health>(); h.currentHealth = userJSON.health; h.OnChangeHealth(); }
void OnAnimation(SocketIOEvent socketIOEvent) { AnimationJSON aniJSON = AnimationJSON.CreateFromJSON(socketIOEvent.data.ToString()); Debug.Log(aniJSON.name); GameObject o = GameObject.Find(aniJSON.name) as GameObject; Debug.Log(aniJSON.motion); Debug.Log(o == null); if (o == null) { return; } SampleAnimation pc = o.GetComponent <SampleAnimation>(); Debug.Log(aniJSON.motion); switch (aniJSON.motion) { case "run": pc.setRun(); break; case "unrun": pc.unRun(); break; case "attack1": pc.setAttack1(); break; case "unattack1": pc.unAttack1(); break; case "attack2": pc.setAttack2(); break; case "unattack2": pc.unAttack2(); break; case "jump": pc.setJump(); break; case "unjump": pc.unJump(); break; } }
void OnPlay(SocketIOEvent socketIOEvent) { print("you joined"); string data = socketIOEvent.data.ToString(); UserJSON currentUserJSON = UserJSON.CreateFromJSON(data); Vector3 position = new Vector3(currentUserJSON.position[0], currentUserJSON.position[1], currentUserJSON.position[2]); Quaternion rotation = Quaternion.Euler(currentUserJSON.rotation[0], currentUserJSON.rotation[1], currentUserJSON.rotation[2]); GameObject p = Instantiate(Chara_4Hero, position, rotation) as GameObject; Controller pc = p.GetComponent <Controller>(); SampleAnimation pa = p.GetComponent <SampleAnimation>(); pa.isLocal = true; pc.isLocalPlayer = true; Transform t = p.transform.Find("Healthbar Canvas"); Transform t1 = t.transform.Find("Player Name"); Text playerName = t1.GetComponent <Text>(); playerName.text = currentUserJSON.name; p.name = currentUserJSON.name; playerNameInput.text = currentUserJSON.name; }
void OnEnable() { tar = (SampleAnimation)target; }