Android - Code working in Unity Remote but not in Build

Hey there

I have the following code

// User has tapped
            if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
            {
                var isTouchingFloor = GetComponent<BoxCollider2D>().IsTouchingLayers(LayerMask.GetMask(Floor));
 
                if (Time.time - touchTime <= 0.5 && isTouchingFloor)
                {
                    Vector2 jumpVelocityToAdd = new Vector2(0f, 30f);
                    myRigidbody2D.velocity += jumpVelocityToAdd;
                }
            }

Which works in Remote but not in build (it is suppose to make the player jump)

Any idea why it is so ?

First of all, unity remote displays everything that the editor sees, and takes input for the editor. Just because something works in the unity editor, or unity remote doesn’t mean that it will work in the build, Unity certainly is weird because of that.

I’m not sure what problem your having, what I would do is try just making the player jump on a touch, and debug with elimination to help narrow down you issue a little more, a script without the timing might look like this:

        if (Input.touchCount > 0)
        {
                touch = Input.GetTouch(1);

                if (touch.phase == TouchPhase.Ended)
                {
                    Vector2 jumpVelocityToAdd = new Vector2(0f, 30f);
                     myRigidbody2D.velocity += jumpVelocityToAdd;
                }
        }

Ok so the problem was that in the start method i was using
myRigidbody2D = FindObjectOfType() instead of myRigidbody2D = GetComponent(). There was some kind of race condition which in my humble opinion should not happen. What a **** headache. Unity should at least give some warning