我正在開發Unity上的2D遊戲。但是我收到了一些錯誤。我不知道如何解決這些問題。我是新手,並從一些鏈接參考。也許我正在創建檢查點,生成點,死亡區,這就是爲什麼會出現錯誤。如何解決這些錯誤
PlayerRespawn.js-
var Player : GameObject;
var spawnPoint: Transform;
function OnTriggerEnter(other : Collider) {
Destroy(other.gameObject);
var P: GameObject = Instantiate(Player,spawnPoint.position,Quaternion.identity);
var sf=Camera.main.GetComponent(SmoothFollow);
sf.target=P.transform;
}
SmoothFollow.js-
var target : Transform;
// The distance in the x-z plane to the target
var distance = 10.0;
// the height we want the camera to be above the target
var height = 5.0;
// How much we
var heightDamping = 2.0;
var rotationDamping = 3.0;
// Place the script in the Camera-Control group in the component menu
@script AddComponentMenu("Camera-Control/Smooth Follow")
function LateUpdate() {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
var wantedRotationAngle = target.eulerAngles.y;
var wantedHeight = target.position.y + height;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position.y = currentHeight;
// Always look at the target
transform.LookAt (target);
}
而且我正在爲─
NullReferenceException
PlayerRespawn.OnTriggerEnter (UnityEngine.Collider other) (at Assets/scripts/PlayerRespawn.js:8)
也許一些JavaScript文件丟失,你應該添加到Assets文件夾。 –
以及如何知道什麼JavaScript文件丟失? –