// Update is called once per frame void Update() { if (follow) { transform.position = new Vector3(x + follow.transform.position.x, y, z + follow.transform.position.z); if (rotateWith) { transform.rotation = Quaternion.Euler(new Vector3(xRotate, follow.transform.rotation.eulerAngles.y + yRotate, zRotate)); } } if (follow && (TrainEngineMainPlayer)follow.GetComponent(typeof(TrainEngineMainPlayer))) { TrainEngineMainPlayer train = (TrainEngineMainPlayer)follow.GetComponent(typeof(TrainEngineMainPlayer)); int trainHelth = train.getHealth(); if (trainHelth < previousHealth) { damaged = true; update = 0; } /*if(trainHelth < 50) * { * State1.GetComponent<Renderer>().enabled = false; * State2.GetComponent<Renderer>().enabled = true; * State3.GetComponent<Renderer>().enabled = false; * }else if(trainHelth < 25) * { * State1.GetComponent<Renderer>().enabled = false; * State2.GetComponent<Renderer>().enabled = false; * State3.GetComponent<Renderer>().enabled = true; * }else * { * State1.GetComponent<Renderer>().enabled = true; * State2.GetComponent<Renderer>().enabled = false; * State3.GetComponent<Renderer>().enabled = false; * }*/ previousHealth = train.getHealth(); if (damaged == true) { update++; this.transform.localPosition = this.transform.localPosition + Random.insideUnitSphere * 1; if (update > 25) { damaged = false; } } /*if(train.reverse()) * { * yRotate = 180; * }else * { * yRotate = 0; * }*/ } }
void Start() { MainTrain = (TrainEngineMainPlayer)GameObject.FindGameObjectWithTag("MainPlayer").GetComponent(typeof(TrainEngineMainPlayer)); MainTrain.gameState = gameState; GameObject[] enemyTrains = GameObject.FindGameObjectsWithTag("EnemyPlayer"); trainsSpawned += enemyTrains.Length; foreach (GameObject enemys in enemyTrains) { TrainEngineEnemy enemy = (TrainEngineEnemy)enemys.GetComponent(typeof(TrainEngineEnemy)); enemy.gameState = gameState; } GameObject[] TrainCars = GameObject.FindGameObjectsWithTag("TrainCar"); foreach (GameObject trainCar in TrainCars) { TrainCarController trainC = (TrainCarController)trainCar.GetComponent(typeof(TrainCarController)); trainC.gameState = gameState; } GameObject[] TrainSpawners = GameObject.FindGameObjectsWithTag("TrainSpawner"); foreach (GameObject TrainSpawner in TrainSpawners) { TrainSpawner spawner = (TrainSpawner)TrainSpawner.GetComponent(typeof(TrainSpawner)); spawner.gameState = gameState; } GameObject[] CoalSpawners = GameObject.FindGameObjectsWithTag("CoalSpawner"); foreach (GameObject CoalSpawner in CoalSpawners) { CoalSpawner spawner = (CoalSpawner)CoalSpawner.GetComponent(typeof(CoalSpawner)); spawner.gameState = gameState; } PlayerPrefs.SetInt("Level", Application.loadedLevel - 2); timeOfLastTrainSpawn = 0; scoreText.text = "score: " + PlayerPrefs.GetInt("Score", 0); switch (gameState) { case 0: //scoreText.text = "trains to Destroy: " + PlayerPrefs.GetInt("Score", 0) + "/" + (totalTrainsSpawned); break; case 1: break; case 2: break; case 3: totalTrainsSpawned = 30 - PlayerPrefs.GetInt(Zone + "0", 0); scoreText.text = "trains to Destroy: " + PlayerPrefs.GetInt("Score", 0) + "/" + (totalTrainsSpawned); MainTrain.coal = (PlayerPrefs.GetInt(Zone + "1", 0)); int CarsCollected = PlayerPrefs.GetInt(Zone + "2", 0); PlayerPrefs.SetString("zone", Zone); break; } Time.timeScale = 0; //pause game PlayerPrefs.SetInt("Score", 0); //set score for the game to zero (reset it) //load sound bank uint bankID; AkSoundEngine.LoadBank("Trainwrex.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out bankID); AkSoundEngine.PostEvent("Gameplay_Train_Loop_Stop", MainTrain.gameObject); }