团队游戏引擎有摄像头跟随脚本变换根据汽车选择的脚本变化?

时间:2013-11-10 18:02:57

标签: unity3d selector unityscript

OVERALL GOAL: Have the camera change target to the selected car

我是团结游戏引擎的新手并且遇到了一些问题。

所以,我有一个成功的汽车选择器,可以在汽车之间切换,并开始与该汽车匹配。一切都有效。唯一的问题是我的“CarCameraScript”有一个变换变量,它总是3辆车中的一辆。我希望它能够根据选定的车型进行更改。

以下是CarCameraScript的代码

#pragma strict
var car : Transform;
var distance: float = 6.4;
var height: float = 1.4;
var rotationDamping : float = 3.0;
var heightDamping: float = 2.0;
var zoomRatio : float = 0.5;
var DefaultFOV : float = 60;
private var rotationVector : Vector3;

function Start () {

}

function LateUpdate () {
var wantedAngel = rotationVector.y;
var wantedHeight = car.position.y + height;
var myAngel = transform.eulerAngles.y;
var myHeight = transform.position.y;
myAngel = Mathf.LerpAngle(myAngel,wantedAngel,rotationDamping*Time.deltaTime);
myHeight = Mathf.Lerp(myHeight,wantedHeight,heightDamping*Time.deltaTime);
var currentRotation = Quaternion.Euler(0,myAngel,0);
transform.position = car.position;
transform.position -= currentRotation*Vector3.forward*distance;
transform.position.y = myHeight;
transform.LookAt(car);
}
function FixedUpdate () {
var localVilocity = car.InverseTransformDirection(car.rigidbody.velocity);
if (localVilocity.z<-0.5) {
rotationVector.y = car.eulerAngles.y + 180;
} else {
rotationVector.y = car.eulerAngles.y;
}
var acc = car.rigidbody.velocity.magnitude;
camera.fieldOfView = DefaultFOV + acc*zoomRatio;
}

这就是侧面板上的样子。

http://i.stack.imgur.com/lYJP7.jpg

无区域(变换)的区域应该是可变的,取决于当前选择的汽车。

现在,我的另一个脚本是CharacterSelectScript

#pragma strict
//this is the currently selected Player. Also the one that will be saved to PlayerPrefs
var selectedPlayer : int = 0;

function Update() 
{ 
if (Input.GetMouseButtonUp (0)) {
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;

    if (Physics.Raycast (ray, hit, 100))
        {
                // The pink text is where you would put the name of the object you want to click on (has attached collider).

                 if(hit.collider.name == "Player1") 
            SelectedCharacter1(); //Sends this click down to a function called "SelectedCharacter1(). Which is where all of our stuff happens.

                if(hit.collider.name == "Player2")
                SelectedCharacter2();

                if(hit.collider.name == "Player3")
                SelectedCharacter3();
        } 
        else
        {
        return;               
        }
    } 
}

function SelectedCharacter1() {
    Debug.Log ("Character 1 SELECTED"); //Print out in the Unity console which     character was selected.
    selectedPlayer = 1;
    PlayerPrefs.SetInt("selectedPlayer", (selectedPlayer));
}

function SelectedCharacter2() {
    Debug.Log ("Character 2 SELECTED");
    selectedPlayer = 2;
    PlayerPrefs.SetInt("selectedPlayer", (selectedPlayer));
}

function SelectedCharacter3() {
    Debug.Log ("Character 3 SELECTED");
    selectedPlayer = 3;
    PlayerPrefs.SetInt("selectedPlayer", (selectedPlayer));
}

我如何获得它以便SelectedPlayer在第一个脚本中更改转换? 有什么想法吗?

我也有预制脚本,这可能并不重要。 另外,我应该将两个脚本合并为一个吗?

OVERALL GOAL: Have the camera change target to the selected car

0 个答案:

没有答案