So I’m working on a Shoot() method that takes several float params (speedOfShot, Bursts, etc.).
I want to create an option for the bullet to have an optional FollowMode, where it follows the player in certain ways. For that I created the enum:
namespace UnityEngine
{
public enum FollowMode
{
Line,
ZigZag
}
}
I also created the Attribute:
[AttributeUsage(AttributeTargets.Method,Inherited = true, AllowMultiple = false)]
public class CallMethodAttribute : Attribute
{
private readonly FollowMode mFollowMode;
public CallMethodAttribute(FollowMode FollowMode)
{
mFollowMode = FollowMode;
}
public FollowMode FollowMode
{
get { return mFollowMode; }
}
}
and the implementation:
public class FollowModeImplementation : MonoBehaviour {
[CallMethod(FollowMode.Line)]
public static void Line()
{
Debug.Log("In Line");
//Do something
}
[CallMethod(FollowMode.ZigZag)]
public static void ZigZag()
{
Debug.Log("In ZigZag");
//Do something
}
}
What I’m trying to accomplish is when I put in the parameters into the call of Shoot(params), once I get to FollowMode I’ll have the option to choose between them (like in ForceMode in RigidBody) and that in Shoot(params) a function will run according to that selected FollowMode.
I’ve looked up some ways and they all seem to refer towards a dictionary, but I can’t manage to create such a dictionary that takes a FollowMode key and a method value, or even an int key and a method value.
I might be going down the completely wrong way, any help would be appreciated!