BrettM
5/19/2019 - 5:50 AM

[Array] Changing Enemy Colour on Spacebar

public class Player : MonoBehavior
{
  
  //anything that has the enemy script attached to it
  public Enemy[] enemies;
  
  private void Update()
  {
    if (Input.GetKeyDown(KeyCode.Space))
    {
      ChangeColour();
    }
  }
  
  private void ChangeColour()
  {
    foreach (var enemy in enemies)
    {
      enemy.GetComponent<Renderer>().material.color = Color.red;
    }
  }