using UnityEngine;
public class test : MonoBehaviour {
string conmponentName = "TestComponent";
Type c;
private void Start()
{
c = Type.GetType(conmponentName);
}
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
(GetComponent(c) as Behaviour).enabled = false;
}
if (Input.GetKeyDown(KeyCode.A))
{
(GetComponent("TestComponent") as Behaviour).enabled = true;
}
}
}
Unity通过字符串添加组件
最新推荐文章于 2024-08-06 09:12:06 发布