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 ?
Answer by Haykys · Apr 22, 2019 at 08:52 PM
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
Answer by StretchyPizza67 · Apr 19, 2019 at 09:46 PM
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;
}
}
Your answer
Follow this Question
Related Questions
Smooth position transform with swipe controls ? 0 Answers
Buttons for Player movement 0 Answers
Touch Controls to make an object interested in another object 1 Answer
Not working Update() on android 0 Answers