using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float fSpeed = 100; public AudioClip explosionSound; private Vector3 v3fStartingPos; //TODO: Uncomment this after GUIController is created. //private GUIController m_pGUIController; //Called on start up void Start() { v3fStartingPos = transform.position; //TODO: Uncomment this after GUIController is created. /*//Get the GUIController so we know whether or not to update. m_pGUIController = GameObject.FindGameObjectWithTag("GUIController").GetComponent("GUIController") as GUIController;*/ } //Called once per physics update void FixedUpdate() { //TODO: Uncomment this after creating the GUIController /*//Just return if game is inactive if (!m_pGUIController.IsGameActive()) return;*/ float fMoveHorizontal = Input.GetAxis("Horizontal"); float fMoveVertical = Input.GetAxis("Vertical"); rigidbody.AddForce(new Vector3(fMoveHorizontal, 0.0f, fMoveVertical) * fSpeed * Time.fixedDeltaTime); } //Called whenever the Player collides with a trigger void OnTriggerEnter(Collider pTrigger) { if (pTrigger.tag == "FallCatcher") OnDeath(); else if (pTrigger.tag == "Mine") { //Use local audio clip instead so sound is centered on player after respawn /*AudioSource pExplosionAudio = pTrigger.GetComponent(typeof(AudioSource)) as AudioSource; pExplosionAudio.PlayOneShot(pExplosionAudio.clip);*/ OnDeath(); //This must be done after calling OnDeath, so the player position has already been reset. AudioSource.PlayClipAtPoint(explosionSound, transform.position); } } //Call when the player dies void OnDeath() { //Reset position and restore start menu transform.position = v3fStartingPos; m_pGUIController.ResetStartMenu(); } }