- Home /
Send Message not working!
Hello everyone, It seems to be a simple but I can't know whats wrong.
I have an empty game object with tag modelHolder. I attached the script "InstantiatePrefab" to it.
function Start () {
prefab = Instantiate (myHouse, gameObject.transform.position , Quaternion.identity); prefab.transform.parent = transform;
var script : ChangeCursor = prefab.AddComponent(ChangeCursor);
}
function CreateNext() { Destroy(prefab); }
And here's the code for "ChangeCursor"
function OnMouseUp() {
if(isPlotted) {
isPlotted = false; var obj= GameObject.FindWithTag ("modelHolder");
obj.SendMessage("CreateNext"); } }
I want simply to call the function CreateNext in the script "InstantiatePrefab", when the drag is over and the mouse is up. any solution?
Would it be possible to reformat your code so that it is readable. You can edit your post and make the code formatted correctly.
Answer by hijinxbassist · Jun 01, 2012 at 12:54 AM
Instead of using send message(which doesnt work, send message sends that call to all the scripts on the GO calling it, see http://unity3d.com/support/documentation/ScriptReference/Component.SendMessage.html>ref), just call the function.
obj.GetComponent(Script).CreateNext();