You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingUnityEngine;usingSystem.Collections;namespaceObserverPattern{publicclassGameController:MonoBehaviour{publicGameObjectsphereObj;//The boxes that will jumppublicGameObjectbox1Obj;publicGameObjectbox2Obj;publicGameObjectbox3Obj;//Will send notifications that something has happened to whoever is interestedSubjectsubject=newSubject();voidStart(){//Create boxes that can observe events and give them an event to doBoxbox1=newBox(box1Obj,newJumpLittle());Boxbox2=newBox(box2Obj,newJumpMedium());Boxbox3=newBox(box3Obj,newJumpHigh());//Add the boxes to the list of objects waiting for something to happensubject.AddObserver(box1);subject.AddObserver(box2);subject.AddObserver(box3);}voidUpdate(){//The boxes should jump if the sphere is cose to origoif((sphereObj.transform.position).magnitude<0.5f){subject.Notify();}}}}
```'
==ASolution
Removing the observer from the observed. This breaks a dependency (whichis what we want).
```c#
usingUnityEngine;publicinterfaceIObserver{voidWatch();}