void Start() { GameObject playerObj = (GameObject)PhotonNetwork.LocalPlayer.TagObject; carController = playerObj.GetComponent <Car_Control>(); // 0 low, 1 medium, 2 high if (QualitySettings.GetQualityLevel() == 0) { // Turn off all VFX for low quality foreach (VisualEffect vfx in dustStormVFX) { vfx.Stop(); vfx.gameObject.SetActive(false); } foreach (ParticleSystem vfx in fireBrazierVFX) { vfx.Stop(); vfx.gameObject.SetActive(false); } } else if (QualitySettings.GetQualityLevel() == 1) { // Turn off some VFX for medium quality dustStormVFX[0].gameObject.SetActive(true); dustStormVFX[0].Play(); dustStormVFX[1].gameObject.SetActive(true); dustStormVFX[1].Play(); dustStormVFX[2].Stop(); dustStormVFX[2].gameObject.SetActive(false); dustStormVFX[3].Stop(); dustStormVFX[3].gameObject.SetActive(false); foreach (ParticleSystem vfx in fireBrazierVFX) { vfx.gameObject.SetActive(true); vfx.Play(); } } else if (QualitySettings.GetQualityLevel() == 2) { // Turn on all VFX for high quality foreach (VisualEffect vfx in dustStormVFX) { vfx.gameObject.SetActive(true); vfx.Play(); } foreach (ParticleSystem vfx in fireBrazierVFX) { vfx.gameObject.SetActive(true); vfx.Play(); } } }
public void busStartState() { print("Bus state is: " + state); Car_Control cc = GameObject.Find("Car_Spawner").GetComponent <Car_Control>(); if (cc.shouldIInstantiateSet2) { cc.set2Instantiation(cc.busLocation); } transform.Translate(0, 0, movingSpeed * Time.deltaTime); if (this.transform.position.z >= 2) { changeState("busRightTurnState"); print("Bus is changing state to: " + state); } }
public void raceCarStartState() { print("Race car state is: " + state); Car_Control cc = GameObject.Find("Car_Spawner").GetComponent <Car_Control>(); if (cc.shouldIInstantiateSet1) { cc.set1Instantiation(cc.raceCarLocation); } transform.Translate(0, 0, movingSpeed * Time.deltaTime); if (this.transform.position.z >= 18.5f) { changeState("raceCarFirstRightTurnState"); print("Race Car is changing state to: " + state); } }
void FixedUpdate() { foreach (Car_Control c in cars) { if (c.alive) { car = c; } } if (car) { transform.position = new Vector3(car.gameObject.transform.position.x, car.gameObject.transform.position.y, -10); transform.rotation = car.gameObject.transform.rotation; } }
// Instantiate new dead car across all clients when a player dies and make sure car control is turned off public void SetCarDead() { Car_Control carControl = this.gameObject.GetComponent <Car_Control>(); carControl.MotorForce = 0; carControl.SteerForce = 0; carControl.enabled = false; World.currentWorld.playersAlive--; dead = true; if (photonView.IsMine) { cameraRig = GameObject.FindGameObjectWithTag("CameraRig").GetComponent <CameraController>(); cameraRig.SetGameOverPosition(); chargeMeterImg.SetActive(false); } if (PhotonNetwork.IsMasterClient) { object[] customInitData = new object[] { thisBody.velocity, thisBody.angularVelocity }; if (this.gameObject.tag.Equals("ThinCar")) { PhotonNetwork.InstantiateSceneObject("Destroyed_ThinCar", this.transform.position, this.transform.rotation, 0, customInitData); } else { PhotonNetwork.InstantiateSceneObject("Destroyed_ThickCar", this.transform.position, this.transform.rotation, 0, customInitData); } } Destroy(this.gameObject); }
private void OnEnable() { GameObject localPlayer = (GameObject)PhotonNetwork.LocalPlayer.TagObject; if (localPlayer != null) { if (localPlayer.GetPhotonView().ViewID == World.currentWorld.playerList[0].playerID) { GameObject winnerObj = World.currentWorld.playerList[0].playerGameObject; Car winnerCar = winnerObj.GetComponent <Car>(); winnerCar.RemoveBomb(); CameraController cameraRig = GameObject.FindGameObjectWithTag("CameraRig").GetComponent <CameraController>(); cameraRig.SetGameOverPosition(); Car_Control winnerControl = winnerObj.GetComponent <Car_Control>(); winnerControl.enabled = false; winnerControl.MotorForce = 0; winnerControl.SteerForce = 0; byte evCode = 4; // Custom Event 4: Used as "DisplayLeaderboard" event object[] content = new object[] { }; // Name of random car to recieve the bomb after past bomb holder blows up RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All }; SendOptions sendOptions = new SendOptions { Reliability = true }; PhotonNetwork.RaiseEvent(evCode, content, raiseEventOptions, sendOptions); } } }
// Events called in other scripts are processed here. One client will send an event and all players will call it public void OnEvent(EventData photonEvent) { byte eventCode = photonEvent.Code; // Event for when cars collide and bomb must transfer from one car to another if (eventCode == CarCollision) { object[] data = (object[])photonEvent.CustomData; // Get the Photon ID's of both cars involved in car collision short bombHolderID = (short)data[0]; short targetID = (short)data[1]; // Get the Gameobjects of both cars GameObject bombHolder = PhotonNetwork.GetPhotonView(bombHolderID).gameObject; GameObject target = PhotonNetwork.GetPhotonView(targetID).gameObject; // Getting the car components of the gameobjects so we can set and remove bombs Car bombHolderCar = bombHolder.GetComponent <Car>(); Car targetCar = target.GetComponent <Car>(); // If the target car isn't dead (so the bomb doesn't get lost) if (bombHolderCar.hasBomb && !targetCar.dead) { bombHolderCar.hasBomb = false; targetCar.hasBomb = true; // transfer bomb to car collided with bombHolderCar.RemoveBomb(); targetCar.SetBomb(); bombHolderCar.timeHeld = targetCar.timeHeld = 0; // set timeHeld back to zero so when it gets bomb again it has to wait to transfer // Timer decrease is increased everytime the bomb transfers, e.g. (maxTime - timerDecrease) World.currentWorld.timerDecrease += 1; World.currentWorld.startTime = PhotonNetwork.Time; // Decrease timer's max time everytime transfer occurs World.currentWorld.bombTimer = World.currentWorld.maxBombTimer = Mathf.Clamp(30 - World.currentWorld.timerDecrease, 5, 30); } } else if (eventCode == BombHolderDies) { object[] data = (object[])photonEvent.CustomData; short bombHolderID = (short)data[0]; short targetID = (short)data[1]; bool isGameOver = (bool)data[2]; GameObject bombHolder = PhotonNetwork.GetPhotonView(bombHolderID).gameObject; GameObject target = PhotonNetwork.GetPhotonView(targetID).gameObject; Car bombHolderCar = bombHolder.GetComponent <Car>(); Car targetCar = target.GetComponent <Car>(); if (World.currentWorld.playerList.Exists(t => t.playerGameObject == bombHolder)) { World.UnityPlayer bombPlayer = World.currentWorld.playerList.Find(t => t.playerGameObject == bombHolder); World.currentWorld.playerList.Remove(bombPlayer); } bombHolderCar.RemoveBomb(); bombHolderCar.SetCarDead(); playerRanks.Push(PhotonNetwork.GetPhotonView(bombHolderID).Owner); if (!isGameOver) { targetCar.SetBomb(); // transfer bomb to car collided with bombHolderCar.timeHeld = targetCar.timeHeld = 0; // set timeHeld back to zero so when it gets bomb again it has to wait to transfer // Timer decrease is increased everytime the bomb transfers, e.g. (maxTime - timerDecrease) World.currentWorld.timerDecrease += 1; World.currentWorld.startTime = PhotonNetwork.Time; // Decrease timer's max time everytime transfer occurs World.currentWorld.bombTimer = World.currentWorld.maxBombTimer = Mathf.Clamp(30 - World.currentWorld.timerDecrease, 5, 30); } else { targetCar.RemoveBomb(); } } else if (eventCode == FirstBombHolder) { object[] data = (object[])photonEvent.CustomData; short targetID = (short)data[0]; GameObject target = PhotonNetwork.GetPhotonView(targetID).gameObject; Car targetCar = target.GetComponent <Car>(); targetCar.SetBomb(); targetCar.timeHeld = 0; // set timeHeld back to zero so when it gets bomb again it has to wait to transfer World.currentWorld.startTime = PhotonNetwork.Time; // Decrease timer's max time everytime transfer occurs World.currentWorld.bombTimer = World.currentWorld.maxBombTimer = Mathf.Clamp(30 - World.currentWorld.timerDecrease, 5, 30); // Timer decrease is increased everytime the bomb transfers, e.g. (maxTime - timerDecrease) World.currentWorld.timerDecrease += 1; } else if (eventCode == DisplayLeaderboard) { // Add the last living player (the winner) to the player ranks stack playerRanks.Push(PhotonNetwork.GetPhotonView(World.currentWorld.playerList[0].playerID).Owner); int stackSize = playerRanks.Count; // List the end game leaderboard based on when the player was pushed to the playerRank stack for (int i = 0; i < stackSize; i++) { leaderboardListings[i].SetPlayerInfo(playerRanks.Pop()); } } else if (eventCode == GameStart) { // Allow player control of their car and show ability UI once everyone has connected if (PhotonNetwork.LocalPlayer.TagObject != null) { GameObject playerObj = (GameObject)PhotonNetwork.LocalPlayer.TagObject; chargeMeter.SetActive(true); waitingText.SetActive(false); Car_Control carControl = playerObj.GetComponent <Car_Control>(); carControl.SetInputsActive(true); } } }
public void whenToInstantiate1() { Car_Control cc = GameObject.Find("Car_Spawner").GetComponent <Car_Control>(); cc.shouldIInstantiateSet1 = true; }
private void FixedUpdate() { GameObject[] cars = GameObject.FindGameObjectsWithTag("Car"); bool state = false; foreach (GameObject car in cars) { state |= car.GetComponent <Car_Control>().alive; } if (!state) { List <NeuralNet> nets = new List <NeuralNet>(); for (int i = 0; i < cars.Length; i++) { nets.Add(cars[i].GetComponent <Car_Control>().net); } nets.Sort(new NetComp()); nets.Reverse(); Debug.Log("-----------------"); Debug.Log(nets[0] == nets[1]); Debug.Log(nets[0].score); Debug.Log(nets[1].score); Debug.Log(nets[2].score); Debug.Log(nets[0].nl[0].n.Count); Debug.Log(nets[1].nl[0].n.Count); Debug.Log(nets[2].nl[0].n.Count); Debug.Log(nets[0].nl[0].n[0].b); Debug.Log(nets[1].nl[0].n[0].b); Debug.Log(nets[2].nl[0].n[0].b); Debug.Log("-----------------"); NeuralNet[] newNets = new NeuralNet[cars.Length]; for (int i = 0; i < newNets.Length; i++) { while (true) { int r = Random.Range(0, 5); if (Random.Range(0, nets[0].score) < Mathf.Abs(nets[r].score) + 10) { newNets[i] = nets[r]; newNets[i].score = 0; break; } } } newNets[0] = nets[0]; newNets[0].score = 0; newNets[1] = nets[0]; newNets[1].score = 0; newNets[1] = nets[1]; newNets[1].score = 0; newNets[1] = nets[1]; newNets[1].score = 0; for (int i = 0; i < cars.Length; i++) { Car_Control c = cars[i].GetComponent <Car_Control>(); c.transform.position = s.transform.position; c.transform.rotation = s.transform.rotation; if (i < 4) { c.net = newNets[Mathf.FloorToInt(i / 2)]; } else { if (i > cars.Length - 5) { NeuralNet nn = new NeuralNet(); nn.inicNet(Random.Range(1, 10), Random.Range(1, 10), 2); c.net = nn; } else { c.net = newNets[Random.Range(0, newNets.Length)].mutateNet(); } } c.alive = true; c.net.score = 0; } gen++; } }