我收到错误 NullReferenceException: Object reference not set to an instance of an object ThirdPersonCamera.Update () (at Assets/scripts/ThirdPersonCamera.cs:24)
我的代码:
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);
}
}
我尝试更改脚本执行顺序,但没有任何效果。我不知道怎么了。