Why would only one part of code work but the rest not? No compile errors in code. The only part of the code that works is the (Input.GetKeyDown(keycode.Space)), everything else does not
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class Player_Movement : MonoBehaviour {
public float speed = 5.0f;
public Transform snapLeft;
public Transform snapRight;
public Transform snapCenter;
public bool triggerCheck;
public GameObject player;
public float move;
public float jump;
private GameObject cube;
public bool disable = false;
public static int distance;
public static Text distanceText;
public AudioSource switchLanes;
public float i;
public bool isleft;
public int currentScore;
void Start ()
{
distance = 0;
move = 1f;
//jump = 0f;
switchLanes = GetComponent<AudioSource>();
isleft = false;
player.GetComponent<Animation>().Play("run");
}
// Reset Jump
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "Player") {
//jump = 0f;
}
}
void Update()
{
// Slow down time
if (Input.GetKey(KeyCode.Space))
{
if (Time.timeScale == 1.0f)
{
Time.timeScale = 0.5f;
}
}
// Resume Speed
if (Input.GetKeyUp(KeyCode.Space))
{
if (Time.timeScale < 1.0f)
{
Time.timeScale = 1.0f;
}
}
distance = distance + 1;
distanceText.text = "Distance: " + distance.ToString();
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) /* && jump == 0f)*/
{
if (gameObject.tag == "Player")
{
if (disable == false)
{
//player.GetComponent<Animator>().Play("Jump");
player.GetComponent<Animator>().Play("New_Jump");
// jump = 1f;
}
}
}
// Slide under object (Scale Collider)
/* if (Input.GetKeyDown(KeyCode.S) && jump == 0f)
{
//if (gameObject.tag == "Player")
{
player.GetComponent<CharacterController>().height = .9f;
player.GetComponent<CharacterController>().center = new Vector3(0, .45f, 0);
disable = true;
player.GetComponent<Animator>().Play("Slide");
StartCoroutine("Wait");
}
}
*/
// Snap Left
if (Input.GetKeyDown (KeyCode.A) && move == 1f || Input.GetKeyDown (KeyCode.LeftArrow) && move == 1f) {
if (gameObject.tag == "Player") {
Debug.Log("Move_Left");
transform.position = snapLeft.transform.position;
move = 0f;
switchLanes.Play ();
//i = 4f;
}
//if (isleft == true) {
//move = 0f;
//}
}
// Set Center from right
if (Input.GetKeyDown (KeyCode.A) && move == 2f|| Input.GetKeyDown (KeyCode.LeftArrow) && move == 2f) {
if (gameObject.tag == "Player") {
transform.position = snapCenter.transform.position;
Debug.Log ("snap center from RIGHT");
move = 1f;
Debug.Log ("value of move =" + move);
switchLanes.Play ();
}
}
// Snap Right
if (Input.GetKeyDown (KeyCode.D) && move == 1f || Input.GetKeyDown (KeyCode.RightArrow) && move == 1f ) {
if (gameObject.tag == "Player") {
transform.position = snapRight.transform.position;
Debug.Log ("snap full RIGHT from center");
move = 2f;
Debug.Log ("value of move =" + move);
switchLanes.Play ();
}
}
// Snap Center from left
if (Input.GetKeyDown (KeyCode.D) && move == 0f || Input.GetKeyDown (KeyCode.RightArrow) && move == 0f ) {
if (gameObject.tag == "Player") {
transform.position = snapCenter.transform.position;
Debug.Log ("snap center from left");
move = 1f;
Debug.Log ("value of move =" + move);
switchLanes.Play ();
}
}
}
// Reset Character Controller
/* IEnumerator Wait() {
yield return new WaitForSeconds(1);
player.GetComponent<CharacterController>().height = 1.85f;
player.GetComponent<CharacterController>().center = new Vector3(0, .9f, 0);
disable = false;
}
}
Comment
Have you tried putting Debug.Log into your if statements and see which work and which don't.