【发布时间】:2021-10-24 23:23:32
【问题描述】:
MissingReferenceException:“Transform”类型的对象已被销毁,但您仍在尝试访问它。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;
// Update is called once per frame
void LateUpdate()
{
if (target.position != null)
{
Vector3 desiredPosition = target.position + offset;
Vector3 smoothPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothPosition;
}
else
{
transform.position = new Vector2(0, 0);
}
}
}
【问题讨论】:
-
谁破坏了目标?