- Home /
How to check for a mouse drag
I have a mouse orbit script, and also a script that shoots when the left mouse button is clicked. However, whenever I drag, the gun also shoots. How can I check to see if the mouse button has been dragged, and only fire the gun when this is false?
Yeah what flapy says, it will be easy to help you once we see some code.
Thank you for the reference, martin.
I instantiate a bullet gameObject when the user clicks.
ok, here is some code that I use:
public void Update()
{
if(isEquipped == true)
{
if (Input.Get$$anonymous$$ouseButtonUp(0)&&isDragging == false)
{
onItemClicked();
}
}
}
public void on$$anonymous$$ouseDrag()
{
isDragging = true;
}
public void onItemClicked()
{
if(itemType == itemTypes.WeaponRanged&&isDragging == false)
{
GameObject bullet = Instantiate(Resources.Load("Items/Weapons/Bullet")) as GameObject;
bullet.GetComponent<Bullet>().gunBarrel = transform.FindChild("Cylinder").gameObject;
}
}
I am aware that there is nothing to disable isDragging, but the bullet still shoots regardless.
Edit: In the reference, it says:
On$$anonymous$$ouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
This will not work, as the user can drag anywhere to turn the camera
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Instantiate and Scale with Mouse Click. 1 Answer
How to properly set the position clicked by the mouse? 0 Answers
GetMouseButtonDown(1) true in multiple frames 1 Answer
Simulate Mouseclick with a kinect. 1 Answer