I'm using Unity Ads on my application. Everything works fine but I want to add an feature which handles the Ad button interactivity whether the Ad is ready or not, through the whole app lifetime.
The simplest solution I've coded consists in checking the availability of the ads within the update()
method:
public class AdButton : MonoBehaviour
{
// Some stuff here
void Update()
{
if (myButton)
myButton.interactable = Advertisement.IsReady(placementId);
}
}
but I also thought about using Actions
events:
public class AdsManager : MonoBehaviour
{
public static event Action<bool> AdReady;
// Some stuff here
void update()
{
adReady?.invoke(Advertisement.isReady(placementId));
}
}
public class AdButton : MonoBehaviour
{
// Some stuff here
void OnEnable()
{
AdsManager.AdReady += RefreshButton;
}
void RefreshButton(bool interactivity)
{
myButton.interactable = interactivity
}
void OnDisable()
{
AdsManager.AdReady -= RefreshButton;
}
}
The problem is that I'm new in Unity and I'm a little bit scared about the update()
method. I've been reading that it's easy to overload the application due to the nature of that function (called once per frame).
Should I be worried about these lines of code or calling every frame these instructions don't slow down my application?
Thanks for your help.
Simo