Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Dan903c21 · Oct 25, 2016 at 03:29 PM · c#unity 5

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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Oct 25, 2016 at 03:59 PM 0
Share

Have you tried putting Debug.Log into your if statements and see which work and which don't.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Nav Mesh Question 0 Answers

Particles appearing behind background image 0 Answers

how do i remember a just instantiated prefab as a variable gameobject? 1 Answer

Return key triggering a button OnClick? 1 Answer

Objects are created in the same location. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges