Click on gameObject With Mouse

Hi I’m trying to write a script attached to an object so that in the web player, I can mouse click on something, and it has an action.

I haven’t seen it in the tutorials yet, closest is that you pass over something or step on something, but this is a FPS type interface and I want to click on things in the environment.

thanks for any direction

you need to look at raycasting. search for it here on there forums and you will find some examples

There is an example of using a raycast for this purpose here. Also, check out the OnMouseDown function.

Thank you this is exactly what i’m looking for.

Hello guys, i used Andeeeee’s method and it works, but when the player clicks an object the only commands that work are the change level commands (Application.LoadScene()). Any other code i used does not work. Does anyone know why?

please post a script / code snippet so we can see what you are trying to achieve and what might be going wrong

Its ok i fixed it. When i clicked the camera was casting a ray using ScreenPointToRay that converts 2d to 3d. When that ray hits an transform something happents. That “something” was not working… till now :smile:. I wanted to use an function in the object that the ray its with the classic method >

GameObject name;
name = GameObject.FindWithTag(“tagname”);

Finaly i fixed it with > transform.SendMessage(“func”);