2024-02-19 21:26:17 -06:00
|
|
|
using UnityEngine;
|
|
|
|
using System.Collections;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
public enum GameMode {
|
|
|
|
idle,
|
|
|
|
playing,
|
|
|
|
levelEnd
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MissionDemolition: MonoBehaviour {
|
|
|
|
static private MissionDemolition s; // a private Singleton
|
|
|
|
[Header("Set in Inspector")]
|
|
|
|
public Text uitLevel; // The UIText_Level Text
|
|
|
|
public Text uitShots; // The UIText_Shots Text
|
|
|
|
public Text uitButton; // The Text on UIButton_View
|
|
|
|
public Vector3 castlePos; // The place to put castles
|
|
|
|
public GameObject[] castles; // An array of the castles
|
|
|
|
[Header("Set Dynamically")]
|
|
|
|
public int level; // The current level
|
|
|
|
public int levelMax; // The number of levels
|
|
|
|
public int shotsTaken;
|
|
|
|
public GameObject castle; // The current castle
|
|
|
|
public GameMode mode = GameMode.idle;
|
|
|
|
public string showing = "Show Slingshot" ; // FollowCam mode
|
|
|
|
|
|
|
|
void Start() {
|
|
|
|
s = this; // Define the Singleton
|
|
|
|
level = 0;
|
|
|
|
levelMax = castles.Length;
|
|
|
|
StartLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartLevel() {
|
|
|
|
// Get rid of the old castle if one exists
|
|
|
|
if (castle != null ) {
|
|
|
|
Destroy(castle);
|
|
|
|
}
|
|
|
|
// Destroy old projectiles if they exist
|
|
|
|
GameObject[] gos = GameObject.FindGameObjectsWithTag("Projectile");
|
|
|
|
foreach (GameObject pTemp in gos) {
|
|
|
|
Destroy(pTemp);
|
|
|
|
}
|
|
|
|
// Instantiate the new castle
|
|
|
|
castle = Instantiate<GameObject>(castles[level]);
|
|
|
|
castle.transform.position = castlePos;
|
|
|
|
shotsTaken = 0;
|
|
|
|
// Reset the camera
|
|
|
|
SwitchView("wShow Both");
|
|
|
|
ProjectileLine.s.Clear();
|
|
|
|
// Reset the goal
|
|
|
|
Goal.goalMet = false;
|
|
|
|
UpdateGUI();
|
|
|
|
mode = GameMode.playing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateGUI() {
|
|
|
|
// Show the data in the GUITexts
|
|
|
|
uitLevel.text = "Level: " + (level + 1) + "of " + levelMax;
|
|
|
|
uitShots.text = "Shots Taken: " + shotsTaken;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
UpdateGUI();
|
|
|
|
|
|
|
|
// Check for level end
|
|
|
|
if ((mode == GameMode.playing) && Goal.goalMet) {
|
|
|
|
// Change mode to stop checking for level end
|
|
|
|
mode = GameMode.levelEnd;
|
|
|
|
// Zoom out
|
|
|
|
SwitchView("Show Both" );
|
|
|
|
// Start the next level in 2 seconds
|
2024-02-22 00:29:49 -06:00
|
|
|
Invoke("NextLevel", 2f);
|
2024-02-19 21:26:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NextLevel() {
|
|
|
|
level++;
|
|
|
|
if (level == levelMax) {
|
|
|
|
level = 0;
|
|
|
|
}
|
|
|
|
StartLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SwitchView(string eView = "") {
|
|
|
|
if (eView == "") {
|
|
|
|
eView = uitButton.text;
|
|
|
|
}
|
|
|
|
showing = eView;
|
|
|
|
switch (showing) {
|
2024-02-22 00:29:49 -06:00
|
|
|
case "Show Slingshot":
|
2024-02-19 21:26:17 -06:00
|
|
|
FollowCam.POI = null;
|
|
|
|
uitButton.text = "Show Castle";
|
|
|
|
break;
|
|
|
|
|
2024-02-22 00:29:49 -06:00
|
|
|
case "Show Castle":
|
2024-02-19 21:26:17 -06:00
|
|
|
FollowCam.POI = s.castle;
|
|
|
|
uitButton.text = "Show Both" ;
|
|
|
|
break;
|
|
|
|
|
2024-02-22 00:29:49 -06:00
|
|
|
case "Show Both":
|
2024-02-19 21:26:17 -06:00
|
|
|
FollowCam.POI = GameObject.Find("ViewBoth" );
|
|
|
|
uitButton.text = "Show Slingshot";
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Static method that allows code anywhere to increment shotsTaken
|
|
|
|
public static void ShotFired() {
|
|
|
|
s.shotsTaken++;
|
|
|
|
}
|
|
|
|
}
|