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);
}
}