void OnPlay(SocketIOEvent socketIOEvent) { print("you joined"); startMenuCamera.gameObject.SetActive(false); string data = socketIOEvent.data.ToString(); print("your JSON data was recieved"); PlayerJSON currentUserJSON = PlayerJSON.CreateFromJSON(data); print("your JSON was created : " + data); Vector3 position = new Vector3(currentUserJSON.playerPosition[0], currentUserJSON.playerPosition[1], currentUserJSON.playerPosition[2]); print("your name isssssssssssssssss "); Quaternion rotation = Quaternion.Euler(currentUserJSON.playerRotation[0], currentUserJSON.playerRotation[1], currentUserJSON.playerRotation[2]); print("your name isssssssssssssssss "); GameObject p = Instantiate(player, position, rotation) as GameObject; MultiPlayerController pc = p.GetComponent <MultiPlayerController>(); Transform t = p.transform.Find("Healthbar Canvas"); Transform t1 = t.transform.Find("Player Name"); Text playerName = t1.GetComponent <Text>(); playerName.text = currentUserJSON.name; pc.isLocalPlayer = true; p.name = currentUserJSON.name; GameObject Eye = p.transform.Find("OVRCameraRig").gameObject; Eye.gameObject.SetActive(true); print("your name is " + currentUserJSON.name); }
void OnCollisionEnter(Collision collision) { MultiPlayerController player = collision.gameObject.GetComponent <MultiPlayerController>(); //If player is not null, it takes damage if (player != null) { player.IsDamaged(25); } Destroy(gameObject); }
public void RotateAndMove() { // rotate head (... TODO: something not right with this) Vector3 mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition); float angle = Mathf.Atan2(mousePos.x, mousePos.y) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward * -1); // -1 for inverted z-axis MultiPlayerController childScript = this.transform.GetChild(0).GetComponent <MultiPlayerController>(); float speed = childScript.GetSpeed(); //Debug.Log(speed); // move head //transform.position = Vector2.MoveTowards(transform.position, mousePos, GetSpeed()); transform.position = Vector2.MoveTowards(transform.position, mousePos, speed); }
private void createPlayerServer(object sender, MessageEventArgs e) { Debug.Log("reciviendo respuesta"); PlayerListResponse response = PlayerListResponse.CreateFromJSON(e.Data); foreach (var user in response.users) { UnityThread.executeInUpdate(() => { GameObject p = Instantiate(multiPlayerPrefact, new Vector3(-8, -1, 0), Quaternion.identity); MultiPlayerController con = p.GetComponent <MultiPlayerController>(); con.init(user); }); } NetworkingController networking = GameMaster.getNetworkingController(); networking.stopListenOnMessage(createPlayerServer, responseName); }
void OnOtherPlayerConnected(SocketIOEvent socketIOEvent) { print("Someone else Joined "); string data = socketIOEvent.data.ToString(); UserJSON userJSON = UserJSON.CreateFromJSON(data); Debug.Log("userJSON is ganerated : " + data); Vector3 position = new Vector3(userJSON.playerPosition[0], userJSON.playerPosition[1], userJSON.playerPosition[2]); Quaternion rotation = Quaternion.Euler(userJSON.playerRotation[0], userJSON.playerRotation[1], userJSON.playerRotation[2]); GameObject o = GameObject.Find(userJSON.name) as GameObject; Debug.Log("O is : " + o); if (o != null) { return; } Debug.Log("Again O is : " + o); GameObject p = Instantiate(player, position, rotation) as GameObject; Debug.Log(userJSON.name + " : body is generated "); GameObject EyeCamera = p.transform.Find("Other Head Avator").gameObject; EyeCamera.gameObject.SetActive(true); GameObject OtherRightHand = p.transform.Find("Other R Hand").gameObject; OtherRightHand.gameObject.SetActive(true); GameObject OtherLeftHand = p.transform.Find("Other L Hand").gameObject; OtherLeftHand.gameObject.SetActive(true); MultiPlayerController pc = p.GetComponent <MultiPlayerController>(); Transform t = p.transform.Find("Healthbar Canvas"); Transform t1 = t.transform.Find("Player Name"); Text playerName = t1.GetComponent <Text>(); playerName.text = userJSON.name; pc.isLocalPlayer = false; p.name = userJSON.name; Debug.Log("Joining player name is : " + p.name); Health h = p.GetComponent <Health>(); h.currentHealth = userJSON.health; h.OnChangeHealth(); }
public void SpawnWakizashis(NetworkManager.WakizashiJSON wakizashisJSON) { foreach (NetworkManager.WakizashiJSON wakizashiJSON in wakizashisJSON.wakizashis) { if (wakizashiJSON.health <= 0) { continue; } Vector3 position = new Vector3(wakizashiJSON.wakizashiPosition[0], wakizashiJSON.wakizashiPosition[1], wakizashiJSON.wakizashiPosition[2]); Quaternion rotation = Quaternion.Euler(wakizashiJSON.wakizashiRotation[0], wakizashiJSON.wakizashiRotation[1], wakizashiJSON.wakizashiRotation[2]); GameObject newWakizashi = Instantiate(wakizashi, position, rotation) as GameObject; newWakizashi.name = wakizashiJSON.name; MultiPlayerController pc = newWakizashi.GetComponent <MultiPlayerController>(); pc.isLocalPlayer = false; Health h = newWakizashi.GetComponent <Health>(); h.currentHealth = 100; h.OnChangeHealth(); h.destroyOnDeath = true; h.isWeapon = true; } }
// Update is called once per frame void Update() { if (gameStarted) { timeLeft -= Time.deltaTime * timePenalty; foreach (Slider slider in sliders) { slider.value = timeLeft; } if (timeLeft <= 0) { GetComponentInChildren <TrailRenderer>().transform.SetParent(null); MultiPlayerController mpc = FindObjectOfType <MultiPlayerController>(); if (mpc != null) { mpc.Looser = gameObject; } GameMaster.instance.GameOver(); GetComponent <PlayerDeathParticlesController>().SpawnEffect(); Destroy(gameObject); } } }
void Start() { MultiPlayerController pc = GetComponent <MultiPlayerController>(); isLocalPlayer = pc.isLocalPlayer; }