How to assign a function as a Var

Hi guys, I have a few triggers that will always call functions, but these functions change though out game play .
So far what I have isn’t working

//#pragma strict
var FunA : Function ;
var FunB : Function ;
var FunC : Function ;
var FunD : Function ; 

function Start () {
FunD = DFun ;
FunC = CFun ;
FunB = BFun ;
FunA = AFun ;
}

function Update () {

}

function DFun (){

print("FunD Activated  ") ;

}

function CFun (){

print("FunC is ON ") ;
}

function BFun (){

print("FunD is ON ") ;
}

function AFun (){

print("FunD is ON ") ;
}

What’s the end result that you’re trying to do? I only ask because everything above the DFun function looks pointless.

Do you just want to call a function on a different script? That’s covered here: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.html

What’s the problem? If you call FuncA(), AFun is called. What exactly is not working?

It sounds to me like what he wants are delegates which, I believe, are not supported in UnityScript.

The code above works fine for me.

Yes they are. Windows in OnGUI wouldn’t work otherwise, for one thing.

–Eric

I stand corrected then. Thanks. :slight_smile:

What I wanted was something to change what function is triggered when FunA is called from an in game trigger .

This would make more sense to illustrate what I mean .

var OnlyFun : Function ;

function FunA() {
print("FunA")}

function FunB {
print("FunB")
}

function Start ()
{
OnlyFun = FunA ;
yield WaitForSecounds(5);
OnlyFun = FunB ; 
}

function Update() {
OnlyFun;
}

I’m sure theirs an easier , or better way to do this , maybe using switches ?

I have it working !

var OnlyFun : Function ;

 

function FunA() {

print("FunA");}

 

function FunB (){

print("FunB");

}

 

function Start ()

{

OnlyFun = FunA ;

yield WaitForSeconds(5);

OnlyFun = FunB ; 

}

 

function Update() {

OnlyFun();

}