【Unity】讓Scene的相機看向選定的GameObject

以下幾個Unity提供的API是關鍵

Selection.selectionChanged //監聽Scene或者Hierarchy窗口中選中項的改變
Selection.activeGameObject //當前選中的GameObject
SceneView.lastActiveSceneView.LookAt //看向目標點的接口

完整代碼如下:

//在合理的地方加上監聽, 比如Editor的OnEnable函數之類的
Selection.selectionChanged += OnSelectionChange;
//...

void OnSelectionChange()
{
    SceneView.lastActiveSceneView.LookAt(Selection.activeGameObject.transform.position);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章