Placing game objects on click

Hello I was wondering if to be able to place a game object when I click if I would have to attach the script to the terrain. Also what would I use to say ‘place object’ in java script. Thanks for help

I don’t understand you quite well, if you want to create gameObject from script, as well I would recommend you to use Instantiate function to create your object. here.http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html Now, you say you want to create the gameObject when a click event displays, so I would recommend you to instantiate the object inside the OnMouseEnter function of your own.

Sorry, I was looking for a way to place a game object on my terrain when i click. I will look into the information that you posted. The one question that I have now is do I attach this script to my terrain or to the object I want to place? Thank you for help:)

so you want to create a object on the clicked position on the terrain?

if so you’ll want to ray cast the terrain, and spawn the object at the hits position.

Something like this:

var raycastPosition = Input.mousePosition; // This will not actually give you the correct mouse position, you need to do something else to get the right position…
var hit : RaycastHit;
if (Physics.Raycast (raycastPosition, -Vector3.up, hit)){
// Create your object here
}

Yeah, I will look into this. Thanks