Hi
Title pretty much says it all. How can I call a funtion thats in a different script (in C#)?
Heres my setup:
Script 1:
public class BipAnimScriptSegments : MonoBehaviour {
public void ArmAnimation(){
animation.CrossFade("Arm");
}
public void LegAnimation(){
animation.CrossFade("Leg");
}
}
Script 2:
public class GUIScript : MonoBehaviour {
public BipAnimScriptSegments target;
void OnGUI () {
GUI.Box (new Rect (10,10,100,90), "Animations");
if (GUI.Button (new Rect (20,40,80,20), "Arm")) {
target.ArmAnimation();
}
if (GUI.Button (new Rect (20,70,80,20), "Leg")) {
target.LegAnimation();
}
}
}
When I click a button in the GUI I get the follow error: “Object reference not set to an instance of an object” and it points to “target.ArmAnimation();”.
What am I missing here?
Thanks.