player can only access items in correct scenes
This commit is contained in:
@@ -75,6 +75,7 @@ public class EnemyPatrol : MonoBehaviour {
|
||||
IEnumerator Defeat() {
|
||||
this.gameObject.GetComponent<BoxCollider2D>().enabled = false;
|
||||
animator.Play("Explosion");
|
||||
this.gameObject.GetComponent<AudioSource>().Play();
|
||||
yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
|
||||
this.gameObject.GetComponent<BoxCollider2D>().enabled = true;
|
||||
this.gameObject.SetActive(false);
|
||||
|
||||
@@ -16,6 +16,7 @@ public class PlayerBehavior : MonoBehaviour
|
||||
[SerializeField] private Launch launcher;
|
||||
[HideInInspector] public bool hasTambourine = true;
|
||||
GameObject tambourine;
|
||||
bool unlockedTambourine;
|
||||
|
||||
[Header("Grappling:")]
|
||||
[SerializeField] public Tutorial_GrapplingGun grapplingGun;
|
||||
@@ -28,7 +29,7 @@ public class PlayerBehavior : MonoBehaviour
|
||||
|
||||
Animator animator;
|
||||
[HideInInspector] public bool playerIsAlive = true;
|
||||
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -41,6 +42,7 @@ public class PlayerBehavior : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
unlockedTambourine = stateController.unlockedTambourine;
|
||||
if (playerIsAlive) {
|
||||
// throw tambourine
|
||||
// if (Input.GetKeyDown(KeyCode.K)) {
|
||||
@@ -110,7 +112,7 @@ public class PlayerBehavior : MonoBehaviour
|
||||
}
|
||||
|
||||
void ThrowTambourine() {
|
||||
if (hasTambourine && !grapplingRope.isGrappling)
|
||||
if (unlockedTambourine && hasTambourine && !grapplingRope.isGrappling)
|
||||
{
|
||||
launcher.ThrowTambourine(forward);
|
||||
hasTambourine = false;
|
||||
@@ -155,6 +157,7 @@ public class PlayerBehavior : MonoBehaviour
|
||||
}
|
||||
else if (col.tag == "instaDeath")
|
||||
{
|
||||
print("player fell in spikes");
|
||||
StartCoroutine(DestroyPlayer());
|
||||
}
|
||||
else if (col.tag == "spawnPoint") {
|
||||
@@ -188,6 +191,7 @@ public class PlayerBehavior : MonoBehaviour
|
||||
collision.gameObject.GetComponent<EnemyPatrol>().DefeatEnemy();
|
||||
} else {
|
||||
StartCoroutine(DestroyPlayer());
|
||||
print("enemy defeated player");
|
||||
}
|
||||
}
|
||||
else if (collision.gameObject.tag == "Projectile") {
|
||||
@@ -197,18 +201,27 @@ public class PlayerBehavior : MonoBehaviour
|
||||
}
|
||||
|
||||
IEnumerator DestroyPlayer() {
|
||||
playerIsAlive = false;
|
||||
if (playerIsAlive) {
|
||||
print("destroyPlayer called");
|
||||
playerIsAlive = false;
|
||||
AudioSource audio = this.gameObject.GetComponent<AudioSource>();
|
||||
audio.Play();
|
||||
|
||||
// animate
|
||||
animator.Play("Die");
|
||||
yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
|
||||
// animate
|
||||
animator.Play("Die");
|
||||
// yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
|
||||
yield return new WaitForSeconds(audio.clip.length);
|
||||
|
||||
this.stateController.SetDeathCanvasActive(true);
|
||||
// this.stateController.SetDeathCanvasActive(true);
|
||||
|
||||
// destroy all tambourines
|
||||
GameObject[] currentTambourines = GameObject.FindGameObjectsWithTag("tambourine");
|
||||
foreach (GameObject tambourine in currentTambourines) {
|
||||
tambourine.GetComponent<TambourineBehavior>().DestroySelf();
|
||||
// destroy all tambourines
|
||||
GameObject[] currentTambourines = GameObject.FindGameObjectsWithTag("tambourine");
|
||||
foreach (GameObject tambourine in currentTambourines) {
|
||||
// tambourine.GetComponent<TambourineBehavior>().DestroySelf();
|
||||
Destroy(tambourine);
|
||||
}
|
||||
|
||||
this.stateController.RespawnPlayer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
Tutorial_GrapplingRope grapplingRope;
|
||||
bool wasGrappling = false;
|
||||
bool unlockedTrumpet;
|
||||
|
||||
//Set all of these up in the inspector
|
||||
[Header("Checks")]
|
||||
@@ -60,6 +61,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
[SerializeField] private LayerMask _groundLayer;
|
||||
|
||||
[HideInInspector] private PlayerBehavior playerBehavior;
|
||||
[HideInInspector] private StateController stateController;
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
@@ -67,7 +69,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
RB = GetComponent<Rigidbody2D>();
|
||||
playerBehavior = this.gameObject.GetComponent<PlayerBehavior>();
|
||||
grapplingRope = playerBehavior.grapplingRope;
|
||||
|
||||
stateController = GameObject.FindGameObjectWithTag("StateController").GetComponent<StateController>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -94,6 +96,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
unlockedTrumpet = stateController.unlockedTrumpet;
|
||||
#region TIMERS
|
||||
LastOnGroundTime -= Time.deltaTime;
|
||||
LastOnWallTime -= Time.deltaTime;
|
||||
@@ -125,7 +128,11 @@ public class PlayerMovement : MonoBehaviour
|
||||
if (IsGrounded()) //checks if set box overlaps with ground
|
||||
{
|
||||
LastOnGroundTime = Data.coyoteTime; //if so sets the lastGrounded to coyoteTime
|
||||
trumpet = 2;
|
||||
if (unlockedTrumpet) {
|
||||
trumpet = 2;
|
||||
} else {
|
||||
trumpet = 0;
|
||||
}
|
||||
wasGrappling = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,14 @@ public class StateController : MonoBehaviour {
|
||||
[Header("Enemies")]
|
||||
GameObject[] enemiesInScene;
|
||||
|
||||
[Header("LevelProgression")]
|
||||
[Header("Level Progression")]
|
||||
GameObject victoryCanvas;
|
||||
|
||||
[Header("Unlocked Items")]
|
||||
[SerializeField] public bool unlockedTrumpet = false;
|
||||
[SerializeField] public bool unlockedTambourine = false;
|
||||
[SerializeField] public bool unlockedClarinet = false;
|
||||
|
||||
void Awake() {
|
||||
// check to see if a state controller already exists
|
||||
if (GameObject.FindGameObjectWithTag("StateController") != null) {
|
||||
@@ -41,7 +46,9 @@ public class StateController : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
|
||||
void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
|
||||
|
||||
#region FIND OBJECTS
|
||||
deathCanvas = GameObject.Find("DeathUICanvas");
|
||||
if (deathCanvas != null) {
|
||||
Button respawnButton = GameObject.Find("RespawnButton").GetComponent<Button>();
|
||||
@@ -73,6 +80,25 @@ public class StateController : MonoBehaviour {
|
||||
if (isPaused) {
|
||||
Unpause();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region UNLOCK ITEMS
|
||||
if (SceneManager.GetActiveScene().name == "GrenouilleVillage") {
|
||||
unlockedTrumpet = false;
|
||||
unlockedTambourine = false;
|
||||
unlockedClarinet = false;
|
||||
}
|
||||
else if (SceneManager.GetActiveScene().name == "GrappleScene") {
|
||||
unlockedTrumpet = true;
|
||||
unlockedTambourine = true;
|
||||
unlockedClarinet = false;
|
||||
}
|
||||
else if (SceneManager.GetActiveScene().name == "ClarinetScene") {
|
||||
unlockedTrumpet = true;
|
||||
unlockedTambourine = true;
|
||||
unlockedClarinet = true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
void OnToggleDebugMenu() {
|
||||
|
||||
Reference in New Issue
Block a user