Hi there, what I want to seems pretty simple, I want to call a function, but be able to change that easily, such as having it like a button:
I can’t really work out how to do it, apart from in a script (just an example I put in):
Okay, I’ll clear things up a little. At the moment my script goes:
if(targets*.hit)*
{ print(“All hit”); //In here I’d call a function, such as example.DoSomething(); //But I don’t want to hard code this function in ^^ //And do it like a button, where you can change the function in // The inspector, without it being hard coded } If you can understand what I mean that’d be awesome if you could reply, thanks
public GameObject targetGo;
public string functionName;
public void DoSendMessage()
{
targetGo.SendMessage(functionName);
}
If you want to call multiple functions then the two variables can be in a list.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class SendMessageInfo
{
public GameObject targetGo;
public string functionName;
}
public class MessageSender : MonoBehaviour {
public List<SendMessageInfo> sendMessageInfos;
public void OnClick() {
foreach(SendMessageInfo smi in sendMessageInfos)
{
smi.targetGo.SendMessage(smi.functionName);
}
}
}