源代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyOutOfBound : MonoBehaviour
{
// Start is called before the first frame update
private float topBound = 40;
private float lowerBound = -40;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position .z > topBound )
{
Destroy(gameObject);
}
else if(transform.position.z < lowerBound )
{
Destroy(gameObject);
}
}
}
解决方法:
一定要注意不要忘记应用到所有预制件上:override-> apply all