Im creating a mobile game using the gyroscope to control with. The idea is that obstacles is coming from the right side going towards the left. All around you are spawning obstacles, even outside of the camera to ensure that the gyroscope actually has a function and you can go in any direction you want.
So i have trouble figuring out how to get check whether my gameobjects in a array is visible to the camera or not - and based on that i want to disable the renderer on those which are not.
public class CameraTest : MonoBehaviour {
public List <Vector3> obsty_position;
public List <GameObject> obsty;
private Camera cam;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
obsty = new List<GameObject>();
obsty.AddRange(GameObject.FindGameObjectsWithTag("Obstacles"));
Debug.Log("Obsty :" + obsty.Count);
EnemyArray();
}
void EnemyArray ()
{
foreach (GameObject g in obsty)
{
if(g.renderer.isVisible == false)
{
g.renderer.disable;
}
}
}
The foreach loop is my idea on how to do it - but it does not work at all.
Hope you guys can figure it out, help me out or point me in the right direction
Kind Regards,
Lars.