Finished book tutorial
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
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
|
||||
Invoke("NextLevel" ,2f );
|
||||
}
|
||||
}
|
||||
|
||||
void NextLevel() {
|
||||
level++;
|
||||
if (level == levelMax) {
|
||||
level = 0;
|
||||
}
|
||||
StartLevel();
|
||||
}
|
||||
|
||||
public void SwitchView(string eView = "") {
|
||||
if (eView == "") {
|
||||
eView = uitButton.text;
|
||||
}
|
||||
showing = eView;
|
||||
switch (showing) {
|
||||
case"Show Slingshot" :
|
||||
FollowCam.POI = null;
|
||||
uitButton.text = "Show Castle";
|
||||
break;
|
||||
|
||||
case"Show Castle":
|
||||
FollowCam.POI = s.castle;
|
||||
uitButton.text = "Show Both" ;
|
||||
break;
|
||||
|
||||
case"Show Both" :
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 106bd9eef544b316b834a5e1a94b2382
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -74,6 +74,8 @@ public class Slingshot : MonoBehaviour
|
||||
projectileRigidbody.velocity = -mouseDelta * velocityMult;
|
||||
FollowCam.POI = projectile;
|
||||
projectile = null;
|
||||
MissionDemolition.ShotFired();
|
||||
ProjectileLine.s.poi = projectile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user