I am trying to make an auto-generating level where each piece destroys itself if you move too far away from it. But I can’t make the code work!
I want a trigger such that, when triggered, it checks the distance from itself to all prefabs of type X. If distance is too big, I want it to destroy those prefabs. In the prefab creation script I have included the line:
clone = Instantiate (prefab, transform.position, Quaternion.identity);
Then, in my GenDestroyer.js:
// var ObjToDestroy : Rigidbody;
var ObjToDestroy : GenNext.clone;
var MaxDistance = 40;
// var distance = Vector3.Distance(ObjToDestroy.transform.position, Player.transform.position);
var distance = Vector3.Distance(transform.position, ObjToDestroy.transform.position);
//Debug.Log(distance);
if (distance > MaxDistance)
{
// Destroy(ObjToDestroy)
Destroy(ObjToDestroy);
}
It has problems, not the least of which it doesn’t recognize the NextGen.clone as a valid type. Any ideas??
Thanks for any help! It is much appreciated.