Passing variable name into function from different script/animation event editor
I'm trying to do something that i think should be fairly simple, but after the last few hours of google searches, I can't find the answer.
I'm trying to pass a variable name into a function. I'm creating an event at the end of an animation and want to enter the variable name to be used in the following script.
using UnityEngine;
using System.Collections;
public class MenuController : MonoBehaviour {
public GameObject ChemMenu;
public GameObject BiologytMenu;
public GameObject PhysicsMenu;
public GameObject MathsMenu;
//Open menu by passing menu name parameter
void openMenu(string menuName) {
menuName.SetActive(true);
}
void closeMenu(string menuName) {
menuName.SetActive(false);
}
}
So basically, at the end of the specific animation, I'm trying to get a UI gameobject that has been added into the inspector using the above script to be activated. So the code in the openMenu function will effectively read "ChemMenu.SetActive(true);" or "BiologyMenu.SetActive(true);" etc depending on name passed into function.
I've tried using string, although obviously the string doesn't have the setactive function. I've also tried assigning the gameobject as the parameter in the event function and it won't allow me to add it.
If anyone can help or point me in right direction, I'd be very grateful!
Your answer
Follow this Question
Related Questions
How to pass a game object through to a function? 2 Answers
Animator Parameter not linking to script variable 0 Answers
Multiple variables in a function? Like function test (number : float , number1 : float) 0 Answers
How to run a function without certain input variables? 0 Answers
How can i pass a method like a parameter Unity3d C#? 3 Answers