Skip to content

Instantly share code, notes, and snippets.

@moon-goon
Created February 22, 2016 02:12
Show Gist options
  • Save moon-goon/909d819fbac206716b84 to your computer and use it in GitHub Desktop.
Save moon-goon/909d819fbac206716b84 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class StateMachine : MonoBehaviour {
public Transform player;
public Transform TargetObj;
private bool isPaused;
private Renderer myWeapon;
public enum PlayerState {
ResumeState,
PauseState
}
public enum PlayerWeapon {
Banana,
Popsicle,
Dagger
}
PlayerState playerState;
PlayerWeapon playerWeapon;
void Start () {
isPaused = false;
myWeapon = GameObject.Find("Weapon").GetComponent<Renderer>();
}
void OnGUI() {
if (playerState == PlayerState.PauseState) {
GUI.Label(new Rect(1130, 5, 300, 130), "<size=30>Game paused</size>");
}
if (playerState == PlayerState.ResumeState) {
GUI.Label(new Rect(1130, 5, 300, 130), "<size=30>Game resuming</size>");
}
if (playerWeapon == PlayerWeapon.Banana) {
GUI.Label(new Rect(5, 5, 300, 130), "<size=30>Current Weapon : Banana</size>");
}
if (playerWeapon == PlayerWeapon.Popsicle) {
GUI.Label(new Rect(5, 5, 300, 130), "<size=30>Current Weapon : Popsicle</size>");
}
if (playerWeapon == PlayerWeapon.Dagger) {
GUI.Label(new Rect(5, 5, 300, 130), "<size=30>Current Weapon : Dagger</size>");
}
}
void Update () {
if (Input.GetKeyDown(KeyCode.P)) {
playerState = PlayerState.PauseState;
}
if (Input.GetKeyDown(KeyCode.P) && isPaused) {
playerState = PlayerState.ResumeState;
}
if (Input.GetKeyDown(KeyCode.Keypad1)) {
playerWeapon = PlayerWeapon.Banana;
}
if (Input.GetKeyDown(KeyCode.Keypad2)) {
playerWeapon = PlayerWeapon.Popsicle;
}
if (Input.GetKeyDown(KeyCode.Keypad3)) {
playerWeapon = PlayerWeapon.Dagger;
}
}
void LateUpdate() {
switch (playerState) {
case PlayerState.PauseState:
Debug.Log("Game Paused");
Time.timeScale = 0;
isPaused = true;
break;
case PlayerState.ResumeState:
Debug.Log("Game Resuming");
Time.timeScale = 1;
isPaused = false;
break;
}//end of switch(playerState)
switch (playerWeapon) {
case PlayerWeapon.Banana:
Debug.Log("Weapon : Banana");
myWeapon.material.color = Color.yellow;
//do stuff
break;
case PlayerWeapon.Popsicle:
Debug.Log("Weapon : Popsicle");
myWeapon.material.color = Color.magenta;
//do stuff
break;
case PlayerWeapon.Dagger:
Debug.Log("Weapon : Dagger");
myWeapon.material.color = Color.grey;
//do stuff
break;
}//end of switch(playerWeapon)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment