Search Unity

How do I get this to work?

Discussion in 'Scripting' started by yaIi, Oct 13, 2015.

  1. yaIi

    yaIi

    Joined:
    Jun 8, 2015
    Posts:
    7
    Code (CSharp):
    1.  
    2. if (Input.GetKey (KeyCode.Space && Collision2D == true)) {
    3.             transform.position += new Vector3(0F, 9F, 0F);
    4.         }
    5.  
    I know it doesn't work like that but u get the idea?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    in the 'OnCollisionStay' method you could test the input and update the position.

    Or in 'OnCollisionEnter' you could set a flag to true, and in 'OnCollisionExit' set it to false. And then that would signal if you're in one... though technically if you overlap multiple things once you exited the first you'd be set back to false, so really you'd have to have an int that adds in enter, and subtract in exit.