Hi guys,
I have some issue with clicking on the object, I hoped, that when i used tags i will solve the problem, but nope. I want a simple thing, that when i click on the prefab object (cube) i will spawn another object, but my script works so that i can click anywhere an object will spawn 
var thePrefab : GameObject;
var Obj : GameObject;
function Start () {
}
function Update () {
if(Input.GetMouseButtonDown(0) )
{
if(Obj.tag == "Build_Menu")
{
var newStructure : GameObject = Instantiate(thePrefab,Obj.transform.position, Quaternion.identity);
newStructure.transform.localEulerAngles.y = (Random.Range(0,360));
Obj.tag = "Build_Menu2";
}
}
}
I know that there is funciton where i should use RaycastHit, but it’s go out of my mind.
I am just a 3D artist who dabbles in other crafts: D, if there is a patient person to help, I’d be grateful
Antrac1t
oh
thx
but i have little bit problem … i have nonstatic camera so when i use
function OnMouseDown ()
{
Debug.Log("ada");
}
its wok only in specific view 
well, its working for me.
the script is attached to the cube? the cube has some sort of collider attached? you point the mouse over the cube and click in play mode? you have your console set up properly that it shows log messages?
sorry u updated my last reply
its working but only in specific view
… i have script fot moving camera + zoom in/out …
the function should be called regardless of the actual view as the current camera properties are taken into consideration to calculate wether a mouseclick occured or not. so it does not matter if you zoom in our out as long as the mouse is over the object when you click. has the collider proper size or is the object occluded by other (invisible) colliders which intercept the ray?
collider have a proper size and fit on the object + with this object is nothing connected … like i said its working only when i zoom in and click on the edge 
when it does not work theres still the manual method with raycast (last example) .
ok i tried
function Update() {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if(Obj.tag == "Build_Menu")
{
var newStructure : GameObject = Instantiate(thePrefab,Obj.transform.position, Quaternion.identity);
newStructure.transform.localEulerAngles.y = (Random.Range(0,360));
Obj.tag = "Build_Menu2";
}
}
but when i press play, objext are allready spawned …
you have only declared the variables for the raycast but not performed the raycast itself. i only do c# so convert it to your needs, the comments should help to understand whats going on.
void Update()
{
if(Input.GetMouseButtonDown(0) )
{// only take action on mouseclick
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100.0f)) // here is the raycast performed, adapt the distance to your needs
{// we hit something so check if the hit object is the object where this script is attached
if(transform.gameObject == hit.collider.gameObject)
// do your stuff here
}
}
}
yy i rework it and wors but still u must zoom in even if i have
if (Physics.Raycast (ray, hit, 5000))
EDIT
ok now i use
if (Physics.Raycast (ray, 1000))
and it works in any zoom disntace, but i have 2 cubes for spawn and they will spawn together … so guess that i must use TAG to differentiate objects
usually those objects would have the same tags and it is inconvenient and error prone to decide after tags. i had includeda test to check wether the hit gameobject is the same as the one this script is attached to. so if you include this test and run the instantiation in it it should only spawn one object.
if(transform.gameObject == hit.collider.gameObject)
i tried it, but when I click on the object show up error "object reference not set to an instance of an object "
when you double click the error in unity it should bring you to the line it was invoked. all reference types should be checked for null prior to accessing them.
you should also always post your current code with an comment at the line where the error occurs. its hard to guess whats wrong when one can’t see your code.
do you have included my above suggested structure? so that the test is only executed when the raycast has actually hit something?
when i click on the object show up this error, its
function Update() {
if(Obj.tag == "Build_Menu"){
if(Input.GetMouseButtonDown(0)){
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, 1000))
{
if(transform.gameObject == hit.collider.gameObject){ // this line is marked as error ... this code line should be same in C# and JS
var newStructure : GameObject = Instantiate(thePrefab,Obj.transform.position, Quaternion.identity);
newStructure.transform.localEulerAngles.y = (Random.Range(0,360));
Obj.tag = "Build_Menu2";
}
}
}
}
}
}
well, you miss to put the hit into the raycast so it can be filled with the data. so your hit is uninitialized (=null) and the exception is thrown. do
if (Physics.Raycast(ray, out hit, 100.0f))
and include the hit then it is filled by the function and valid. i don’t know how to handle out parameters in unityscript. thats research up to you. usually the language of the examples could be switched but i don’t see the option any more so maybe it has been removed lately. but google should help you to find it out.