Search Unity

Barrel Role

Discussion in 'Scripting' started by scorpian_25, Feb 10, 2016.

  1. scorpian_25

    scorpian_25

    Joined:
    Jul 30, 2015
    Posts:
    2
    I am just beginning with Unity and doing the Space Shooter tutorial. I want to add a code to do a barrel role if the player inputs the left and right key twice. I went to scripting and found GetButton function but I really do not know if I am using it correctly. Any pointers??? With this code I was trying things out seeing but i am pretty sure it probably makes no sense to the compiler.

    if (Input.GetButton("button") && Time.time > 0)
    {
    rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -roll);
    }
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    For working with left/right buttons use GetAxis method (see documentation here):
    Code (csharp):
    1. Input.GetAxis("Horizontal")
    And, Time.time - always will greater then 0, so this piece of code is surplus
     
    Last edited: Feb 10, 2016
  3. scorpian_25

    scorpian_25

    Joined:
    Jul 30, 2015
    Posts:
    2
    I am already using getaxis function. Initial movement of my space craft is moving now do I use only that function in my if statement to get player input twice or double tap.