//<summary> // called on start, initialize stuff //</summary> void Start() { //Scale graphics to screen size Utilities.setCameraViewForScreen(); // add all levels onto level list ProgressManager.InitiateLevelList(); // unlock the first two levels ProgressManager.unlockedLevels.Add(ProgressManager.levelList[0]); ProgressManager.unlockedLevels.Add(ProgressManager.levelList[3]); // set up kid GameObject kid = GameObject.FindGameObjectWithTag("Kid"); kid.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite> ("Graphics/" + ProgressManager.chosenKid); if (Resources.Load <Sprite>("Graphics/" + ProgressManager.chosenKid) == null) { Debug.LogWarning("Could not load sprite"); } // grow kid animation GrowKid(); // load background music onto the word tree director GameObject dir = GameObject.Find("WordTreeDirector"); dir.AddComponent <AudioSource>().clip = Resources.Load("Audio/BackgroundMusic/WordTree") as AudioClip; // play background music if attached to director if (dir.GetComponent <AudioSource>().clip != null) { dir.GetComponent <AudioSource>().volume = .25f; dir.GetComponent <AudioSource>().Play(); } else { Debug.LogWarning("Could not load audio file"); } // subscribe home button to gestures GameObject home = GameObject.Find("HomeButton"); home.AddComponent <GestureManager>().AddAndSubscribeToGestures(home); // set up lock - lock starts out as closed GameObject Lock = GameObject.Find(ProgressManager.lockStatus); if (ProgressManager.lockStatus == "") { Lock = GameObject.Find("LockClosed"); } // subscribe lock to gestures Lock.AddComponent <GestureManager>().AddAndSubscribeToGestures(Lock); // move lock to front LeanTween.moveZ(Lock, -2f, .01f); // find level icons GameObject[] gos = GameObject.FindGameObjectsWithTag("LevelIcon"); foreach (GameObject go in gos) { // if level is not unlocked yet, make level icon disappear if (!ProgressManager.IsLevelUnlocked(go.name)) { Color color = go.GetComponent <Renderer>().material.color; color.a = 0f; go.GetComponent <Renderer>().material.color = color; } // if level has been unlocked if (ProgressManager.IsLevelUnlocked(go.name)) { // subscribe level icon to gestures go.AddComponent <GestureManager>().AddAndSubscribeToGestures(go); // start pulsing level icon go.AddComponent <PulseBehavior>().StartPulsing(go); // if level has not been completed if (!ProgressManager.IsLevelCompleted(go.name)) { // darken level icon go.GetComponent <SpriteRenderer>().color = Color.grey; } // if level has been completed else { // brighten level icon go.GetComponent <SpriteRenderer>().color = Color.white; } } } // if lock has been previously opened if (ProgressManager.lockStatus == "LockOpen") { // keep showing all level icons on word tree ProgressManager.UnlockAllLevels(); } }
// Handle all tap events. Trigger actions in response. private void tappedHandler(object sender, EventArgs e) { // get the gesture that was sent to us // this gesture will tell us what object was touched TapGesture gesture = sender as TapGesture; ITouchHit hit; GameObject go = gesture.gameObject; // get info about where the hit object was located when the gesture was // recognized - i.e., where on the object (in screen dimensions) did // the tap occur? if (gesture.GetTargetHitResult(out hit)) { // want the info as a 2D point ITouchHit2D hit2d = (ITouchHit2D)hit; Debug.Log("TAP on " + gesture.gameObject.name + " at " + hit2d.Point); } // if kid is tapped - stop pulsing kid, make kid bounce up and down, make kid speak if (go.tag == "Kid") { go.GetComponent <PulseBehavior>().StopPulsing(go); BounceKid(go); go.AddComponent <AudioSource>().clip = Resources.Load("Audio/KidSpeaking/Intro") as AudioClip; if (go.audio.clip != null) { go.audio.Play(); } // keep track of which kid was tapped on (boy or girl) ProgressManager.chosenKid = go.name; // go to next scene with the word tree StartCoroutine(LoadLevel("2. Word Tree", 2.5f)); } // if a levelIcon is tapped on - make kid "shrink into" the levelIcon if (go.tag == "LevelIcon") { ShrinkKid(new Vector3(go.transform.position.x, go.transform.position.y, -2)); // keep track of what level Icon was tapped: stores the name of the current level ProgressManager.currentLevel = go.name.Substring(0, go.name.Length - 1); // go to next scene StartCoroutine(LoadLevel("3. Choose Object", 1f)); } // For each level (category of words, i.e. Animals or Transportation), there are three different modes (games for the user to play): // 1. Learn Spelling // 2. Spelling Game // 3. Sound Game // The name of each level icon has either the number 1, 2, or 3 appended to it. The number corresponds to the mode. // If level icon is tapped - keep track of what mode it is if (go.name.Substring(go.name.Length - 1).Equals("1")) { ProgressManager.currentMode = 1; } if (go.name.Substring(go.name.Length - 1).Equals("2")) { ProgressManager.currentMode = 2; } if (go.name.Substring(go.name.Length - 1).Equals("3")) { ProgressManager.currentMode = 3; } // if a word object is tapped on in the Choose Object scene, load the appropriate scene if (go.tag == "WordObject" && Application.loadedLevelName == "3. Choose Object") { // if the mode is 1, go to Learn Spelling scene if (ProgressManager.currentMode == 1) { Application.LoadLevel("4. Learn Spelling"); } // if the mode is 2, go to Spelling Game scene if (ProgressManager.currentMode == 2) { Application.LoadLevel("5. Spelling Game"); } // if the mode is 3, go to Sound Game scene if (ProgressManager.currentMode == 3) { Application.LoadLevel("6. Sound Game"); } // keep track of the name of the word object that was tapped on (the current word) ProgressManager.currentWord = gesture.gameObject.name; } // play word's sound when tapped if (go.tag == "WordObject" && Application.loadedLevelName != "3. Choose Object") { go.audio.Play(); } // if home button is tapped, go back to the intro scene if (go.name == "HomeButton") { Application.LoadLevel("1. Intro"); } // if tree button is tapped, shrink kid into tree icon and go back to Word Tree scene if (go.name == "TreeButton") { ShrinkKid(go.transform.position); StartCoroutine(LoadLevel("2. Word Tree", 1f)); } // if back button is tapped, go to Choose Object scene if (go.name == "BackButton") { Application.LoadLevel("3. Choose Object"); } // if sound button is tapped, play word's sound if (go.name == "SoundButton") { GameObject.FindGameObjectWithTag("WordObject").audio.Play(); } // if hint button is tapped, show a hint if (go.name == "HintButton") { // if scene is Spelling Game, show a letter hint if (Application.loadedLevelName == "5. Spelling Game") { CollisionManager.ShowLetterHint(); } // if scene is Sound Game, show a sound hint if (Application.loadedLevelName == "6. Sound Game") { CollisionManager.ShowSoundHint(); } } // if the closed lock icon is tapped, unlock all levels of the word tree if (go.name == "LockClosed") { ProgressManager.UnlockAllLevels(); ProgressManager.lockStatus = "LockOpen"; // change status of lock to open // move closed lock icon to behind the background and disable touch gestures LeanTween.moveZ(go, 3f, .01f); go.GetComponent <GestureManager>().DisableGestures(go); // move open lock icon in front of background and subscribe to touch gestures GameObject lockOpen = GameObject.Find("LockOpen"); LeanTween.moveZ(lockOpen, -2f, .01f); lockOpen.AddComponent <GestureManager>().AddAndSubscribeToGestures(lockOpen); } // if the open lock icon is tapped, remove all levels not yet completed from word tree if (go.name == "LockOpen") { ProgressManager.RelockLevels(); ProgressManager.lockStatus = "LockClosed"; // change status of lock to closed // move open lock icon to behind background and disable touch gestures LeanTween.moveZ(go, 3f, .01f); go.GetComponent <GestureManager>().DisableGestures(go); // move closed lock icon in front of background and subscribe to touch gestures GameObject lockClosed = GameObject.Find("LockClosed"); LeanTween.moveZ(lockClosed, -2f, .01f); lockClosed.AddComponent <GestureManager>().AddAndSubscribeToGestures(lockClosed); } // if any button is tapped, darken the button briefly to indicate to user that // tap gesture has been registered if (go.tag == "Button") { LeanTween.color(go, Color.grey, .01f); LeanTween.color(go, Color.white, .01f).setDelay(.2f); } }