Input.Touches Mouse position Shooting Buttons
Hello everyone i am really stuck at the moment am would appreciate any help if possible. I have my game where i move the player up and down with 2 buttons on the bottom left of screenshot.
I also have a button over the entire screen for tap to shoot and this moves the weapon to my finger position where i have tapped and it shoots towards that position using mouse.position.
Now the problem is when i am on my android device and i am moving up and down but when i also tap to shoot the gun it moves towards my up and down buttons and this is not what i want.
Here is my Tap to shoot button code!
public void ShootButton()
{
timer = 0;
Face = true;
//if finger presses Shootbutton
//then activate this
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
// subtracting the position of the player from the mouse position.
difference.Normalize(); //normalizing the vector meaning all the sum of the vector will be = to 1.
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;//find the angle in degree.
WeaponTrans.transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset);
if (reloading == false)
{
if (fireRate == 0)
{
{
Shoot();
}
}
else
{
if (Time.time > timeToFire)
{
timeToFire = Time.time + 1 / fireRate;
Shoot();
}
}
}
}
Answer by muarda · Jan 25, 2019 at 12:07 AM
Why nobody answered this question!!!! If you found a solution, it would be nice if you share it with us!!!!!!!!!! After 2 hours finally I solved with this same problem
https://www.youtube.com/watch?time_continue=274&v=EVZiv7DLU6E
https://forum.unity.com/threads/checking-if-a-touch-position-is-over-a-button.344811/