player can only access items in correct scenes

This commit is contained in:
Sam
2023-05-01 01:52:42 -07:00
parent d3893d3f0e
commit 932af31dc9
12 changed files with 406 additions and 22 deletions

View File

@@ -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();
}
}
}