0
我得到了錯誤的NullReferenceException:未將對象引用設置到對象 ThirdPersonCamera.Update()的一個實例(在資產/腳本/ ThirdPersonCamera.cs:24)團結5第三人腳本錯誤
我代碼:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using UnityEngine.SocialPlatforms;
using UnityEngine.UI;
using UnityStandardAssets.Utility;
public class ThirdPersonCamera : MonoBehaviour {
[SerializeField]Vector3 cameraOffset;
[SerializeField]float damping;
Transform cameraLookTarget;
Player localPlayer;
void Awake() {
GameManger.Instance.OnLocalPlayerJoined += HandleOnLocalPlayerJoined;
}
void HandleOnLocalPlayerJoined (Player player) {
localPlayer = player;
cameraLookTarget = localPlayer.transform.Find("cameraLookTarget");
if (cameraLookTarget == null) {
cameraLookTarget = localPlayer.transform;
}
}
// Update is called once per frame
void Update() {
Vector3 targetPosition = cameraLookTarget.position + localPlayer.transform.forward * cameraOffset.z +
localPlayer.transform.up * cameraOffset.y +
localPlayer.transform.right * cameraOffset.x;
transform.position = Vector3.Lerp(transform.position, targetPosition, damping * Time.deltaTime);
}
}
我試過更改腳本執行順序,但沒有任何工作。我不知道什麼是錯的。