Hi there, I was just wondering if there was any way I could simplify my below code here:
(instead of having to keep duplicating the code every time I make a new sign)
I was thinking the way to do it would be to convert the variable ‘signTouchingName’ into the name of the void function I am calling.
if (signTouching.name == "Sign1") {
GameObject.Find ("MessageBox").GetComponent<MessageText> ().Sign1 ();
} else if (signTouching.name == "Sign2") {
GameObject.Find ("MessageBox").GetComponent<MessageText> ().Sign2 ();
} else if (signTouching.name == "Sign3") {
GameObject.Find ("MessageBox").GetComponent<MessageText> ().Sign3 ();
} else if (signTouching.name == "Sign4") {
GameObject.Find ("MessageBox").GetComponent<MessageText> ().Sign4 ();
} else if (signTouching.name == "Sign5") {
GameObject.Find ("MessageBox").GetComponent<MessageText> ().Sign5 ();
}
Any help appreciated thank you