protected override void Awake() { base.Awake(); Transform createdTransform = Instantiate(otherCarPrefab, otherCarPrefab.transform.position, Quaternion.identity, transform).transform; createdTransform.localPosition = otherCarPrefab.transform.localPosition; OtherCar otherCar = createdTransform.GetComponent <OtherCar>(); animator = otherCar.animator; letterText = otherCar.letterText; }
public void SetPlayerCarBytes(byte playerID, byte[] carBytes) { CalculatedCar calculatedCar = Analyzer.AnalyzeCar(carBytes); if (otherPlayers[playerID] != null && calculatedCar != null) { OtherCar otherCar = otherPlayers[playerID].GetComponent <OtherCar>(); otherCar.TestCar = testCar; otherCar.ApplyCar(calculatedCar); otherCar.PlayerDisplayname = players[playerID].PlayerName; Debug.Log("The car was applied"); } else { if (calculatedCar == null) { Debug.Log("calculatedCar was null"); } else { Debug.Log("otherPlayers was null"); } } }
// Update is called once per frame void Update() { infoRefreshCounter += Time.deltaTime; posSendCounter += Time.deltaTime; if (infoRefreshCounter >= otherPlayersInfoRefreshRate) { infoRefreshCounter = 0f; for (int i = 0; i < 255; i++) { if (players[i] != null) { if (otherPlayers[i] == null && ownID != i) { otherPlayers[i] = (GameObject)Instantiate(prefabOtherCar, Vector3.zero, Quaternion.identity); otherPlayers[i].GetComponent <OtherCar>().ID = (byte)i; if (miniMap != null) { miniMap.AddObject(otherPlayers[i], players[i].PlayerName); } } if (ownID != i) { OtherCar otherCar = otherPlayers[i].GetComponent <OtherCar>(); if (otherCar.Model3DLoaded == false && ownID != i) { network.SendRequestCar(ownID, (byte)i); } } } else { } } } if (posSendCounter >= posSendRate) { network.SendOwnPosition(ownID, testCar.transform.position, testCar.transform.eulerAngles.x, testCar.transform.eulerAngles.y, testCar.transform.eulerAngles.z, 0f, testCar.GetComponent <Rigidbody>().velocity); } for (byte i = 0; i < 255; i++) { if (otherPlayers[i] != null) { otherPlayers[i].transform.position = posInterpol.GetInfoPosition(i); otherPlayers[i].transform.rotation = Quaternion.Euler(posInterpol.GetInfoRotation(i)); } } if (Input.GetKeyDown(KeyCode.Escape)) { openMenu(!menuOpened); } for (int i = 0; i < testCar.GetComponent <TestCar>().ShootingWeapon.Length; i++) { if (testCar.GetComponent <TestCar>().ShootingWeapon[i] != beforeShootings[i]) { network.SendMachinegunButtonPress(ownID, (byte)i, testCar.GetComponent <TestCar>().ShootingWeapon[i]); beforeShootings[i] = testCar.GetComponent <TestCar>().ShootingWeapon[i]; } } }