- Home /
Input.GetMouseButton on multiple objects
Im not sure but can i use this on multiple objects on same scene, by just changing the name of the loaded level?
Put this on, lets say 4 different cubes with different LoadLevel() in one scene, will it work?
function Update () {
if(Input.GetMouseButton(0)) {
Application.LoadLevel ("hc");
}
}
and if the anserw is yes then i have pretty odd problem with all the cubes (with different LoadLevel) leading to same scene with this being only script in scene
Answer by rutter · Oct 26, 2013 at 01:38 AM
Input.GetMouseButton(0)
The above will check if the left mouse button is currently down. It won't check anything, like where the mouse cursor is or which object is being "clicked".
If you want these GameObjects to load a particular level when they're clicked, you're probably better off using something like MonoBehaviour's OnMouseDown() event. The example usage on the script reference even handles your specific use case:
function OnMouseDown() {
Application.LoadLevel("SomeLevel");
}
You could also use Input.mousePosition with Camera.main.ScreenToWorldPoint() or ScreenPointToRay() to interact with objects in your scene.