raycast

I have a script to connect to the main room. I wanted to make sure that when you click with the mouse shows the picture of the broken glass in the position where the mouse is. How can I do? I use the Raycast? who can help me? thanks

If you just want to get mouse position, use Input.mousePosition.

I wanted to make sure that you create an instance of the object every time I click with the mouse on the screen

if(Input.getMouseButtonDown(0){
Instantiate(glass,Input.mousePosition);
}

If you want it to be on the ground where it was clicked, then you would need to use raycast:

I tried that but it does not work … something wrong?

// Finds out whether target is on the left or right side of the screen
var target : Transform;
var bum : GameObject;

function Update () {
var viewPos : Vector3 = camera.WorldToViewportPoint (target.position);
// viewport coordinates range from zero to one
Debug.Log(Input.mousePosition);

if(Input.GetButtonDown (“Fire1”)){
var clone : GameObject = Instantiate(bum, Input.mousePosition, Quaternion.identity);

}
}

You tried the link I gave and it didn’t work? What in your code doesn’t work? Do you think people can read your mind? Did you get an error? Did it not do what you wanted?

ah sorry I thought I had written the code in motivation. I do not by any error but I do not generate any GameObject. I detect the mouse position

You’ll have to work on intantiating your game object. Make sure the camera is pointed at 0,0,0 in the editor, and try instantiating your game object at 0,0,0 in a start function. When you can do that, you can then move on. Otherwise, try to find a tutorial on prefabs and instantiation.

practically now I generate them but I do not display them

// Finds out whether target is on the left or right side of the screen
var target : Transform;
var bum : GameObject;

function Update () {
var viewPos : Vector3 = camera.WorldToViewportPoint(target.position);
// viewport coordinates range from zero to one
Debug.Log(Input.mousePosition);

if(Input.GetButtonDown (“Fire1”)){
Instantiate(bum, Input.mousePosition, Quaternion.identity);

}
}