如何让相机围绕物体旋转

时间:2016-06-01 01:08:25

标签: unity3d camera rotation

我在Unity中使用它作为我的相机脚本来跟随游戏对象:

using UnityEngine;
using System.Collections;

public class CameraMoverScript : MonoBehaviour {

public Transform mainCameraTransform = null;
private Vector3 cameraOffset = Vector3.zero;
public GameObject fish;                //player object
void Start()
{

    mainCameraTransform = Camera.main.transform;

    //Get camera-player Transform Offset that will be used to move the camera 
    cameraOffset = mainCameraTransform.position - fish.gameObject.transform.position;
}

void LateUpdate()
{
    //Move the camera to the position of the playerTransform with the offset that was saved in the begining
    mainCameraTransform.position = fish.gameObject.transform.position + cameraOffset;
}

}

问题是旋转的物体不会影响相机。相机应该围绕物体旋转,使物体旋转后没有任何不同的效果。 非常感谢所有帮助。

1 个答案:

答案 0 :(得分:0)

如果你能够在你的特定项目中,如果你将相机添加为你的游戏对象的子对象,那么对你来说可能是有益的。这样,它跟随并随之旋转。

相关问题