Search Unity

Does this script work?

Discussion in 'Scripting' started by Wallfall_, May 25, 2020.

  1. Wallfall_

    Wallfall_

    Joined:
    May 25, 2020
    Posts:
    6
    Hi
    The other day i made a player movement script and i just wanted to know if this definitely works (like moving with the player's finger) for android phone.(because unity remote 5 doesn't work)
    thanks.

    public float Speedup;
    public GameObject scenemanager;
    public float playerSpeed = 1400;
    public float directionalSpeed = 20;
    public AudioClip scoreup;
    public AudioClip damage;

    // Use this for initialization
    void Start () {
    InvokeRepeating("SpeedUp", 10, 5);
    }

    // Update is called once per frame
    void Update () {

    #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
    float moveHorizontal = Input.GetAxis("Horizontal");
    transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(Mathf.Clamp(gameObject.transform.position.x + moveHorizontal, -2.5f, 2.5f), gameObject.transform.position.y, gameObject.transform.position.z), directionalSpeed * Time.deltaTime);
    #endif
    GetComponent<Rigidbody>().velocity = Vector3.forward * playerSpeed * Time.deltaTime;
    //MOBILE CONTROLS
    Vector2 touch = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, 10f));
    if (Input.touchCount > 0)
    {
    transform.position = new Vector3(touch.x, transform.position.y, transform.position.z);
    }
    }


    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.tag == "scoreup")
    {
    GetComponent<AudioSource>().PlayOneShot(scoreup, 1.0f);

    }

    if (other.gameObject.tag == "triangle")
    {
    GetComponent<AudioSource>().PlayOneShot(damage, 1.0f);
    scenemanager.GetComponent<App_initialize>().GameOver();
    }
    }

    public void SpeedUp()
    {
    playerSpeed+=Speedup;

    }
     
    Last edited: May 25, 2020
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    1. Use code tags.

    2. That's an unreasonable question, in multiple respects:
    a) You haven't specified what "works" means. You're assuming that your goal will be obvious just from reading the code. This is often not the case.
    b) Trying to find all the mistakes in some code just by reading it is very hard (even if you know exactly what it's supposed to do). In most cases, your best strategy is to try actually running the code and see what happens, and go from there.

    So I suggest you make an Android build and try it out.
     
  3. Wallfall_

    Wallfall_

    Joined:
    May 25, 2020
    Posts:
    6
    sorry i forgot to mention that unity remote 5 doesn't work
     
  4. Wallfall_

    Wallfall_

    Joined:
    May 25, 2020
    Posts:
    6
    and for (a) moving with the player's finger
     
    Last edited: May 25, 2020
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    Lurking-Ninja likes this.
  6. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    If you want to develop for Android, you're going to need a way to test on Android for yourself. That's really non-negotiable.

    I happen to have used Unity Remote just a few days ago on an Android device, so I suspect your problem is fixable. But the ultimate test is to actually build for Android and run it directly on an Android device, which doesn't require Unity Remote.

    Computer programming is all about precision. Exactly what finger motions should cause exactly what player motions? But this is academic because of part B.
     
  7. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    you need to get unity remote working, its more important for you to make a thread to get help to get unity remote to work first
     
    StarManta and leftshoe18 like this.
  8. Wallfall_

    Wallfall_

    Joined:
    May 25, 2020
    Posts:
    6
    oh thanks