Search Unity

Key Representation

Discussion in 'Scripting' started by UnityDevUnicord, Oct 17, 2018.

  1. UnityDevUnicord

    UnityDevUnicord

    Joined:
    Oct 17, 2018
    Posts:
    3
    So I am trying to make my cube move with W,A,S,and D but I am trying to assign Space as the jump button but I don't know how and this is the code I have now

    if (Input.GetKey("Keys.Space"))
    {
    rb.AddForce(0, -12, 0);
    }

    Please Help!
     
    Last edited: Oct 17, 2018
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    You adding negative 12 units on the Z axis, open the editor and look at what axis is Z.

    What you want is a POSITIVE value on the Y axis (Y is up in unity)
     
    UnityDevUnicord likes this.
  3. UnityDevUnicord

    UnityDevUnicord

    Joined:
    Oct 17, 2018
    Posts:
    3
    Oh yeah sorry I was messing around with that stuff a long time ago just imagine it is the Y Axis
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    How about showing us your complete script?

    because i feel like you wrote that snippet just for here, Keys.Space should be KeyCode.Space, iirc, this should not compile.

    What is actually happening?
    Do you have any errors in the console on compiling/runtime?
    If so, what are they?
    Do you have the script on the object?
    Do you have a rigidbody on the object?
    Do you have a reference to said rigidbody?

    Give us something to work with man, so many question so little info ;}
     
  5. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
  6. UnityDevUnicord

    UnityDevUnicord

    Joined:
    Oct 17, 2018
    Posts:
    3
    Thanks for the help Sernix and SparrowsNest for the help, It is working now!