2016-06-01 32 views
0

旋轉我用這與在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; 
} 

} 

的問題是,旋轉對象不會影響相機。相機應該圍繞物體旋轉,使得物體旋轉後沒有什麼不同的效果。 所有幫助非常感謝。

+0

也許我不是在理解這個問題,但爲什麼不讓相機成爲對象的孩子。 – Agustin0987

回答

0

Unity3D船隻很多有用的腳本,包括流暢的後續攝像頭,讓你可以使相機遵循競賽對象:

File Path: Assets\Standard Assets\Utility\SmoothFollow.cs 

enter image description here

0

如果您能夠在您的具體項目,它如果您將相機添加爲遊戲對象的子對象,可能會對您有所幫助。這樣,它隨之而來並隨之旋轉。