GetMouseButtonDown works but GetTouch does not
Even though both codes are entirely the same, my prefab bullets only shoots from the mouse click (on my computer) and not the screen touch(on my phone). The gun.rotation works just not the prefab bullets. Anyone have any idea why?
void Update() {
targetRight = GameObject.Find("TargetRight").GetComponent<Transform>();
Vector3 difference = targetRight.transform.position - transform.position;
float angle = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
if (Input.GetMouseButtonDown(0) && Input.mousePosition.x > ScreenWidth /2)
{
gun.rotation = angle;
float distance = difference.magnitude;
Vector2 direction = difference / distance;
direction.Normalize();
fireBulletRight(direction, angle);
}
if (0 < Input.touchCount)
{
if (Input.GetTouch(0).phase == TouchPhase.Began && Input.GetTouch(0).position.x > ScreenWidth / 2 )
{
gun.rotation = angle;
float distance = difference.magnitude;
Vector2 direction = difference / distance;
direction.Normalize();
fireBulletRight(direction, angle);
}
else if (Input.GetTouch(0).phase == TouchPhase.Began && Input.GetTouch(0).position.x < ScreenWidth / 2)
{
transform.rotation = Quaternion.Euler(0, 0, 143);
}
}
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
transform.rotation = Quaternion.Euler(0, 0, 90);
}
}
Answer by awoodenicebox · Mar 03, 2020 at 03:27 PM
I know no one answered this but I'll just put the solution out there so if anyone has an issue like this they could refer to this post. In the middle of my project I had updated the name of my scene. This presented an issue during build time because the build was still looking for my old scene.
You got to go to File -> Build Settings and under where it says Build Settings you must right click the scene and click "remove selection" and then re add scene with new name.