Search Unity

transform not being called every second.

Discussion in 'Scripting' started by W4RH4WK117, Mar 21, 2012.

  1. W4RH4WK117

    W4RH4WK117

    Joined:
    Feb 6, 2011
    Posts:
    129
    Hey guys, it's been a long time since I've used unity.

    Just having trouble with one script that should work properly but it does not call the transform every second but it ignores Time.delta time and jumps to that position.

    Any help would be greatly appreciated.

    Code (csharp):
    1. var moveSpeed:float = 1.0;
    2. var jumpHeight:float = 1.0;
    3.  
    4. function Update ()
    5.  
    6. {
    7. // Constantly moves the cube in the right direction
    8. transform.position.x += moveSpeed * Time.deltaTime;
    9.  
    10. if (Input.GetKeyDown ("space"))
    11. {
    12.  transform.position.y += jumpHeight * Time.deltaTime;
    13. }
    14.  
    15. }
     
  2. tigerfoot

    tigerfoot

    Joined:
    Nov 2, 2009
    Posts:
    132
    When i click space it's Y position does not change at all. But if i put GetKey instead of GetKeyDown then it's Y position changes.
     
  3. W4RH4WK117

    W4RH4WK117

    Joined:
    Feb 6, 2011
    Posts:
    129
    Well that seemed to fix it, thank you kind sir.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    problem with that solution being if you hold the space down, you will keep going up..