In its current state, your script won’t do what you intended. return; on line 22 is called every time, so nothing after that line will ever be reached, and all your script does is incrementing addsing while touchScript.dead is true.
This script could be fixed, but a more elegant solution would be to use events. That way, you don’t have to check at every update if the player’s dead, you just define a method that gets called whenever the player dies, which is what you wanted.
First, in TouchScript, create a UnityEvent and invoke it whenever the player dies.
using UnityEngine.Events;
public class TouchScript
{
...
// Define a new UnityEvent
public UnityEvent onDead = new UnityEvent();
void Die()
{
...
// Invoke it when the player dies
onDead.Invoke()
}
}
Then, in your AdsScript, you have to listen to this event and add a callback.
void Start()
{
addsing = 0f;
DontDestroyOnLoad (this.gameObject);
// Use GameObject.Find only once
GameObject thePlayer = GameObject.Find ("fly");
TouchScript touchScript = thePlayer.GetComponent<TouchScript> ();
// Add listener to the event you just defined
touchScript.onDead.AddListener(onPlayerDead);
}
void onPlayerDead()
{
// Called whenever the player dies
addsing += 1f;
if (addsing == 3)
{
if (Advertisement.IsReady ()) {
Advertisement.Show ();
addsing = 0;
}
}