LiangAction 类
[RequireComponent(typeof(HighlightableObject))]
public class LiangAction : HighLightControl
{
//public HighlightableObject obj;
private void Start()
{
// m_ho.FlashingOn(Color.blue,Color.red,1);
m_ho = GetComponent<HighlightableObject>();
m_ho.ConstantOn(Color.blue);
}
private void OnDestroy()
{
Debug.LogError("我被销毁了");
Destroy(GetComponent<HighlightableObject>());
}
}
配合页面摄像机挂载的脚本中 代码块
GameObject.Find("Cube").AddComponent<LiangAction>();//添加组件
}
if (Input.GetKeyDown(KeyCode.Q))
{
Destroy(GameObject.Find("Cube").GetComponent<LiangAction>());
}
实现效果: 1.点击Cube添加高亮组件 2.字母Q 移除高亮组件 3.显示:cube变蓝 鼠标指上自动变色
[RequireComponent(typeof(....))]
当你添加的一个用了RequireComponent组件的脚本,需要的组件将会自动被添加到game object(游戏物体) 用法:在新建的类前面加 [RequireComponent(typeof(HighlightableObject))] 