Hi. I have already posted something like this but this one is different. In my game the player is climbing up a wall of infinitely instantiated brick walls. A wall is deleted when a certain distance from the player. The only problem is that it only destroy the one wall I’ve assigned it to. How can I make it destroy any game object with the tag “wall” that is a certain distance away. Here is my code now:
using UnityEngine;
using System.Collections;
public class BrickWallTrashCollection : MonoBehaviour {
public GameObject wall;
public Transform player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if( Vector3.Distance( wall.transform.position, player.position ) >= 10f ){
Destroy( wall );
}
}
}
Please help. Thanks!