I am trying to create a screen clear for my enemies but for the ones in the camera's view. The main issue is that all the solutions give me a half way result.
My button Code
void ScreenClear()
{
screenClear = false;
if (Input.GetButtonDown("Fire2"))
{
screenClear = true;
}
}
Screen clearing attmpts
Destroys One at Random
public void OnBecomeVisible()
{
if ((screenClear == true))
{
Destroy(GameObject.FindGameObjectWithTag("Enemy"));
Debug.Log("Found them");
}
}
Does Not Work, Main issue GameObject.Destroy(enemy);, why: enemy apparently does not exist in this current context even thou i have it in the foreach.
Link to the helping code: http://answers.unity3d.com/answers/1143637/view.html;
public void OnBecomeVisible()
{
if (screenClear == true)
{
GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject enemy in enemies);
GameObject.Destroy(enemy);
Debug.Log("Found them");
}
}
Code from another script in game but Cant give extra variables other than tag == "Enemy"
public void OnBecameVisible()
{
if ((tag == "Enemy"))
{
Destroy(gameObject);
Debug.Log("Found them");
}
}
Any help would be appreciated.
↧