Setting Active in the event listener

// Start is called before the first frame update
void Start()
{
UnitActionSystem.Instance.OnBusyChanged += UnitActionSystem_OnBusyChanged;

  gameObject.SetActive(false);
  // Hide();
}

private void UnitActionSystem_OnBusyChanged(object sender, bool isBusy)
{
gameObject.SetActive(isBusy);

  /*if (isBusy)
  {
  	Show();
  }
  else
  {
  	Hide();
  }*/

}

/*private void Show()
{
gameObject.SetActive(true);
}

private void Hide()
{
gameObject.SetActive(false);
}*/

The way I solved this was to just set active directly on the event listener. Is this like bad practice or something? I think he talked about it earlier in the course, but I can’t remember the exact reasoning.

1 Like

This is fine, but perhaps - at some point - you also want to set active/inactive somewhere else in this class. You could call gameObject.SetActive(...) again, but it would be better practice to have this in a Show() or Hide() method, especially if you start having multiple things that need to happen when ‘showing’ or ‘hiding’

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms