- Home /
Duplicate Question
Is i possible to make an instantiated object appear in that exact position, when using a plane as a collider, using Input.MousePosition?
var shinePrefab : GameObject; var clone : GameObject; var x : float; var y : float;
function Start () {
}
function Update () {
if(Input.GetMouseButtonDown(0))
{
Debug.Log("Pressed left click.");
Instantiate (shinePrefab, Input.mousePosition,Vector3(x,y,0), transform.rotation,Quaternion.identity);
//Invoke ("Spawn", Random.Range( 0, 1));
Destroy(GameObject.Find("Shine(Clone)"), 3);
}
if(Input.GetMouseButtonDown(1))
{
Debug.Log("Pressed right click.");
}
if(Input.GetMouseButtonDown(2))
{
Debug.Log("Pressed middle click.");
}
}
You are looking for 'Physics.Raycast()'. There are 1000's of answers on UA with Raycasts as examples. If you search for 'Unity3d Raycast' you will find a number of video tutorials as well. Ans the reference contains examples for the various forms of Physics.Raycast():
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
Follow this Question
Related Questions
How can I add the OnTriggerEnter function to all game objects that I instantiate? 1 Answer
How to Instantiate GameObject on top of collider? (C# 1 Answer
How can I check if an instantiated object collides with another instantiated object? 1 Answer
how to move an object clone to mouse position, i dont understand ? 1 Answer