Hey there! Well here is my problem:
I downloaded a Free Inventory System(Brackeys) And works all fine blah blah. But once i crate a custom effect item and add the script it appears with many errors. If i fix them it doesnt work!
So here is what i seek: I want the Script A to sent a function signal thing to Script B. Script B with this function(Player Stats) Should add 200 Health, how can i make this work? HElp…
ok if I understand you can use BroadcastMessage to exchange information, call functions or another, for example in JS:
public class Listener{
var listenFor : String;
var forwardToMethod : String;
var listeningObject : GameObject;
function Listener(lFor : String, listeningObj : GameObject, method : String){
listenFor = lFor;
forwardToMethod = method;
listeningObject = listeningObj;
}
}
public static class MessageManager{
private var listeners : List.<Listener> = new List.<Listener>();
function RegisterListener(l : Listener){
listeners.Add(l);
}
function SendToListeners(info : String, value : float){
for (var lis in listeners) {
if(lis.listenFor == info ){
lis.listeningObject.BroadcastMessage(lis.forwardToMethod, value, SendMessageOptions.DontRequireReceiver);
}
}
}
}
and than you can use in this way:
//to receive ...
funcion Start(){
MessageManager.RegisterListener(new Listener("Increase Health", gameObject, "HandleMethod"));
}
funcion HandleMethod(value : float){
health += value;
}
//to send ...
MessageManager.SendToListeners("Increase Health", 200f);