Search Unity

  1. Unity 2019.2 is now released.
    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:
    737
    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))