Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Hi I really need help have put over 30 hours into a pc game, I've been working off of many tutourial

Discussion in 'Editor & General Support' started by Therealwardell, Aug 9, 2019.

  1. Therealwardell

    Therealwardell

    Joined:
    Aug 4, 2019
    Posts:
    1
    this is my current player movement script

    using UnityEngine;

    public class PlayerMovement : MonoBehaviour {

    // This is a reference to the Rigidbody component called "rb"
    public Rigidbody rb;

    public float forwardForce = 2000f; // Variable that determines the forward force
    public float sidewaysForce = 500f; // Variable that determines the sideways force

    // We marked this as "Fixed"Update because we
    // are using it to mess with physics.
    void FixedUpdate ()
    {
    // Add a forward force
    rb.AddForce(0, 0, forwardForce * Time.deltaTime);

    if (Input.GetKey("d")) // If the player is pressing the "d" key
    {
    // Add a force to the right
    rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
    }

    if (Input.GetKey("a")) // If the player is pressing the "a" key
    {
    // Add a force to the left
    rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
    }

    if (rb.position.y < -1f)
    {
    FindObjectOfType<GameManager>().EndGame();
    }
    }
    }


    I would like to change this to a mobile game, so I need to somehow learn hoe to make the get key d command and a into button commands. Each button would take up half the screen and when held like a key would add a sideways force to the player. Thanks in advance.
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,904
    Please always use code tags when you post code on the forums. You can learn how to this here: https://forum.unity.com/threads/using-code-tags-properly.143875/

    You can learn how to use touch controls in Unity here: https://docs.unity3d.com/Manual/MobileInput.html
    And you can watch this beginner's tutorial here:


    After that when you have concrete questions, we're here to help.
     
    Joe-Censored likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You say 30 hours like that's a lot or something :p

    You could implement buttons you press on the screen, or what I'd probably do is a virtual joystick. There's a few good assets on the Asset Store for virtual or touch joysticks.
     
  4. Ragegamedude

    Ragegamedude

    Joined:
    Oct 3, 2015
    Posts:
    4
    i dont know if its a good solution but you could use Eventtrigger with pointer enter and exit to set a bool. Did this some years ago in a study project.