I need to get a script, that when I click the left mouse button, it will create a game object. but the game object has to be inserted in a grid if you know what I mean.
1 Answer
1Ok…
I’m not going to write the script for you but I’ll show you where to start.
You can use the Input.GetMouseButtonDown function to run that function ever time the left mouse is clicked. Then use instantiate to spawn an object.
Ex.
var whatever : GameObject;
function FixedUpdate(){
//0 is for when the left button is clicked, 1 is for the right
if(Input.GetMouseButtonDown(0))
instantiate(whatever,transform.position,Quaternion.identity);
}
Don’t really know what you mean by “inserted in a grid” but you can use:
instantiate(whatever, This, And This) to set at the position at which the object is spawned and the rotation of the object.
You might want to look into:
http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
http://unity3d.com/support/documentation/ScriptReference/Input.GetMouseButtonDown.html
Thanks for that.
– Ampler_Games