Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Unity Mobile Controls

Kinda newbie at Unity and all this things and trying to make mobile controls with buttons for my game, but my knowledge not so huge yet, so hope you can help me...

Code:

void Update()

  {

    if (state == State.Alive)

    {

      RespondToThrustInput();

      RespondToRotateInput();

    }

  }




private void RespondToThrustInput()

  {

    if (Input.GetKey(KeyCode.Space))

    {

      ApplyThrust();

    }

    else

    {

      audioSource.Stop();

      thrustParticle.Stop();

    }

  }




private void RespondToRotateInput()

  {

    rigidBody.freezeRotation = true; // TODO remake this weird freeze system later




    float rotationThisFrame = rcsThrust * Time.deltaTime;




    if (Input.GetKey(KeyCode.A)) // TODO button control for mobile

    { 

      transform.Rotate(Vector3.forward * rotationThisFrame);

    }

    else if (Input.GetKey(KeyCode.D))

    {

      transform.Rotate(-Vector3.forward * rotationThisFrame);

    }




    rigidBody.freezeRotation = false; // resume physics control 

}


Maybe this information is useless, but that code from one of udemy cource, in cource game use PC controls like in this code, but I want to build it for android

And one more thing, maybe there's some weird lines of code, but course for very very new to unity and coding and some things that hard to understand for newbies is untold

Answers

  • HNJHNJ Member

    Import the Unity Standard assets crossplatform Input package

    You can also search for some Unity Standard assets crossplatform Input setting up videos.

  • You can use ui buttons for them

Sign In or Register to comment.