- Home /
Instantiated object don't recognize MouseClick.
I have a script that detect the mouse click (OnMouseUp() ).
When I instantiate an object (prefab), the click function does not work. But when I put the object on scene (not via script), it works.
What can i do?
Thanks. (Sorry for my english)
The code for this part is really simple. just : The generator stage1 = (GameObject)Instantiate(nivelPrefab, new Vector3(0,0,0), Quaternion.identity);
the 'click' script:
void On$$anonymous$$ouseUp(){
Debug.Log("worked"); }
There are other things in the Code, but does not interfere.
O$$anonymous$$, firstly you mention that it doesn't recognise $$anonymous$$ouse Click. On$$anonymous$$ouseUp(), detects the release of a mouse button, but that wont be the problem, but just to clear that up first.
On$$anonymous$$ouseUp() and On$$anonymous$$ouseDown() are called only for when pressing the mouse while over a GUIElement or a Collider. (Link: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseUp.html).
In your case, make sure the prefab contains a collider so that the object has one when in the scene. Check that the collider is still there when you instantiate it in script.
Also, if your prefab is declared at the top of the code as a GameObject (lets call it myObj), then you just need to use:
myObj = Instantiate(nivelPrefab, new Vector3(0,0,0), Quaternion.identity);
Let me know how it goes :)
Your answer
Follow this Question
Related Questions
[Solved]Instantiating prefab from a script and destroy it from another one 2 Answers
Network instantiate command do not execute in all client.. 1 Answer
Scripts of instantiated objects 1 Answer
assign different values to prefabs on instantiation 2 Answers
How to have unique instances of script on multiple instances of prefab? 1 Answer