- Home /
Message sender...how to know who send the message
I want to know wich of my game object send message... i want to put the message sender as a target variable? can any one help me!!
it might be best just to add a parameter that tells
some discussion related ...
http://answers.unity3d.com/questions/208018/unityscript-who-called-me-problem.html
Yeah - don't use StackTrace for production purposes - if you need to know who called you pass a parameter or use some other method (static instance member?) to record the sender.
Answer by Sisso · Oct 11, 2012 at 11:24 AM
Use a more complex datastructure in your params.
sender script
// create a array with yours gameobject and a command
var parmas = [ gameObject, "attack" ];
// send to "target" gameobject
target.SendMessage("OnDoSomethingForMe", params);
target script
// event handler
function OnDoSomehtingForMe(params : Object[]) {
// take its parametrs back
var sender = params[0] as GameObject;
var action = parmas[1] as String;
// send back a message
sender.SendMessage("Rejected", action);
}
In params you could pass a Hashtable or your on message class, like:
class Message {
var sender : GameObject;
var action : String;
function Message(sender : GameObject, action : String) {
this.sender = sender;
this.action = action
}
}
target.SendMessage("OnDoSomethingForMe", new Message(gameObject, "attack"));
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Array problem? help please! 1 Answer
Change gameObject of the VAR TARGET HELP!!! 1 Answer
Split a cube into several pieces? 1 Answer
Nested Functions 1 Answer