- Home /
 
 
               Question by 
               thegrandmaster97 · Oct 19, 2020 at 02:49 PM · 
                referenceclassesinterface  
              
 
              How to pass over different scripts, subscribing to the same interface
I have two classes and one Interface "IDelayedTimerClick"
The script "DoubleClickCountdown" implements the interface and needs to pass itself over to the "TimerWithDelay" .The reason why i need an interface is because the script "DoubleClickCountdown" is just one of the many that i can pass over to the "TimerWithDelay"
Right now as it stands, i am not able to get the script in the right way, in order to pass it over.
  public interface IDelayedTimerClick
     {
           void TimerUp();
           void StartCountDown();
     }
 public class DoubleClickCountdown : MonoBehaviour, IDelayedTimerClick
     {
         private TimerWithDelay timerWithDelay;
     
         public  void TimerUp()
         {
             Debug.Log("TimeUp");
             CheckMouseClick.current.FailedDoubleClick();
             timerWithDelay = null;
         }
     
         public  void StartCountDown()
         {
             Debug.Log("About To Start Timer");
     
             timerWithDelay = new TimerWithDelay(1, GetComponent<IDelayedTimerClick>());
         }
     }
 public class TimerWithDelay : MonoBehaviour
 {
     private IDelayedTimerClick scriptObjectRef = null;
     private float startTimeCounter;
     private float endTimeCounter;
     private float delay;
 
     public TimerWithDelay(float delay,  IDelayedTimerClick scriptObject)
     {
         this.delay = delay;
         scriptObjectRef = scriptObject;
         Debug.Log("Started Delay Counter");
         StartCoroutine(CountTimer());
     }
 
     private IEnumerator CountTimer()
     {
         while (true)
         {
             endTimeCounter = Time.time;
             if (endTimeCounter - startTimeCounter > delay)
                 scriptObjectRef.TimerUp();
             yield return new WaitForEndOfFrame();
         }
     }
 }
 
              
               Comment
              
 
               
              Your answer