【发布时间】:2016-12-10 15:26:06
【问题描述】:
我正在我的场景中实例化一个对象,现在我希望相机跟随它我该怎么做? 对象已实例化,但我不知道如何将对象传递给我的相机目标; 而且你不能将实例化的对象拖到检查器
public class TankManager : MonoBehaviour
{
void Start()
{
Instantiate (MenuManager.SelectedCharacter, Vector3.zero, Quaternion.identity);
}}
我的相机代码:
public class FollowCamera : MonoBehaviour{
public Transform target;
public Vector3 offsetPosition;
public Space offsetPositionSpace = Space.Self;
public bool lookAt = true;
private void Update()
{
Refresh();
}
public void Refresh()
{
if(target == null)
{
Debug.LogWarning("Missing target ref !", this);
return;
}
if(offsetPositionSpace == Space.Self)
{
transform.position = target.TransformPoint(offsetPosition);
}
else
{
transform.position = target.position + offsetPosition;
}
if(lookAt)
{
transform.LookAt(target);
}
else
{
transform.rotation = target.rotation;
}
}
}
【问题讨论】:
标签: c# unity3d camera parameter-passing