Unity—string转换为Enum枚举类型

1
2
3
4
5
6
7
8
9
public class Anim : MonoBehaviour
{
    public AnimType animType;

    private void Start()
    {
        animType = (AnimType)System.Enum.Parse(typeof(AnimType), transform.name);
    }
}