x


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?

more ▼

asked Jun 01 '12 at 12:52 AM

moghes gravatar image

moghes
605 17 29 43

Would it be possible to reformat your code so that it is readable. You can edit your post and make the code formatted correctly.

Jun 01 '12 at 03:51 AM kolban
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Instead of using send message(which doesnt work, send message sends that call to all the scripts on the GO calling it, see ref), just call the function.

obj.GetComponent(Script).CreateNext();
more ▼

answered Jun 01 '12 at 12:54 AM

hijinxbassist gravatar image

hijinxbassist
2k 23 31 38

Thanks dude!!

Jun 01 '12 at 01:22 AM moghes
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2086
x184
x33

asked: Jun 01 '12 at 12:52 AM

Seen: 755 times

Last Updated: Jun 01 '12 at 03:51 AM