Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Jump

Discussion in 'Scripting' started by Fekzh21, Feb 14, 2019.

  1. Fekzh21

    Fekzh21

    Joined:
    Dec 29, 2018
    Posts:
    18
    How could I execute this with a button and not with the space.

    Code (CSharp):
    1. public class Salto : MonoBehaviour
    2. {
    3.     public Rigidbody rb;
    4.     void Start()
    5.     {
    6.         rb = GetComponent<Rigidbody>();
    7.        
    8.     }
    9.  
    10.     // Update is called once per frame
    11.     void FixedUpdate()
    12.     {
    13.         if (Input.GetButtonDown("Jump"))
    14.             rb.velocity = new Vector3(0, 20, 0);
    15.     }
    16. }
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    You could hardcode a key to it or change the assignment of Jump in the input manager.

    Code (CSharp):
    1. if(Input.GetKeyDown(Keycode.Whatever))