- Home /
Basic Mouse Click Anywhere for something to happen.
Is this possible with unity 3d? I know it is, but I haven't found a solution for this yet. I tried:
function OnMouseDown ()
{
var snowball = Instantiate(snowballPrefab, GameObject.Find("SSpawnPoint").transform.position, Quaternion.identity); snowball.rigidbody.AddForce(transform.forward * 1000);
}
and it works only if I click the snowball prefab. I would like to make this work by clicking anywhere on the screen. Any help is appreciated. Thank you!
It may help your code readability to hit the enter key, maybe just copy paste formatting trouble though:
Example: A = B; C = D; //Bad
Answer by Bampf · Nov 16, 2010 at 06:09 PM
Yes, it's easily done. See documentation for Input.GetMouseButtonDown or Input.GetButtonDown() for descriptions and code.
Does anyone know the equivalent in the "new input system" in Unity? My specific use case is I made a menu selection that pops up where the cursor is, and now if they click anywhere on the screen, it should disappear.
Answer by LFZ2 · Nov 16, 2010 at 06:49 PM
It is somehow not working for me, I tried Imput.GetMouseButtonDown example, I tried even Input.GetButtonDown()... still no working result it acts like I didn't do nothing.
Answer by LFZ2 · Nov 17, 2010 at 03:47 PM
I made it work! if(Input.GetButtonDown("Fire1")) did the trick:) thank you!
Input.GetButtonDown() is not correct for unity 3.1 Input.GetButton() is correct.
Answer by lll4louis · Apr 14, 2019 at 11:14 AM
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/Input.GetMouseButton.html I found this, for the latest version (today is 14-4-2019) .
Your answer
Follow this Question
Related Questions
Only want to detect button click event 1 Answer
Ignore Clicks on MobileJoysticks? 0 Answers
How do I get my UI Button to play my "fire animation" once? 2 Answers
Create UI raycast like a mouse Click 2 Answers
edit isTrigger by clicking on it, 1 Answer