0
\$\begingroup\$

OK guys i have tried lots of things and researched but cannot find a solution please someone give me hope.. So on my phone when i am playing i want to shoot with a screen button in the canvas that is the entire screen size, and when i click it i can shoot towards where my finger is clicked "This works"... now my problem is whilst i am shooting when i also use my up and down button to move my player at the same time my gun stops moving towards my finger and instead moves towards my up and down buttons.. What can i do to fix this?

public void ShootButton() {

    timer = 0;
    Face = true;
    //if finger is press on 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();
            }
        }
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ So what youy are saying is that when you press your up and down buttons the ShootButton() method is also called? \$\endgroup\$
    – Uri Popov
    Jun 29, 2018 at 8:52
  • \$\begingroup\$ Please add the Update() code so we can help \$\endgroup\$
    – medukrin
    Jun 29, 2018 at 11:53
  • \$\begingroup\$ no no when i press up and down the mouse posiiton is called i only want the mouse position to be blocked by my up and down buttons and work with my shoot button \$\endgroup\$
    – Todd Weiss
    Jun 30, 2018 at 5:55

1 Answer 1

0
\$\begingroup\$

When there are multiple simultaneous touches on the Input.mousePosition is the average of all touch positions. Instead use Input.GetTouch(0).position;

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .