fixed: tambourine ui resets properly on player death

This commit is contained in:
Sam 2023-05-01 16:53:13 -07:00
parent cc694586a4
commit 347b1a0b2c
4 changed files with 64 additions and 26 deletions

View File

@ -3012,6 +3012,18 @@ PrefabInstance:
propertyPath: m_Name
value: GrappleBox (1)
objectReference: {fileID: 0}
- target: {fileID: 1025473297745678352, guid: 94c7d43583a3b46c58e7d4e253eae896, type: 3}
propertyPath: m_Radius
value: 1.85
objectReference: {fileID: 0}
- target: {fileID: 1025473297745678352, guid: 94c7d43583a3b46c58e7d4e253eae896, type: 3}
propertyPath: m_Offset.x
value: 0.33
objectReference: {fileID: 0}
- target: {fileID: 1025473297745678352, guid: 94c7d43583a3b46c58e7d4e253eae896, type: 3}
propertyPath: m_Offset.y
value: -9.03
objectReference: {fileID: 0}
- target: {fileID: 8452658923215583967, guid: 94c7d43583a3b46c58e7d4e253eae896, type: 3}
propertyPath: m_RootOrder
value: -1

View File

@ -55,4 +55,16 @@ public class GameUIController : MonoBehaviour
clarinetUI.GetComponent<Image>().enabled = toggleState;
}
}
public void ResetInstrumentUI() {
if (stateController.unlockedTrumpet) {
ToggleTrumpet(true);
}
if (stateController.unlockedTambourine) {
ToggleTambourine(true);
}
if (stateController.unlockedClarinet) {
ToggleClarinet(true);
}
}
}

View File

@ -41,7 +41,9 @@ public class PlayerBehavior : MonoBehaviour
{ // initialize
_rb = GetComponent<Rigidbody2D>();
stateController = GameObject.Find("StateController").GetComponent<StateController>();
gameUI = GameObject.FindGameObjectWithTag("GameUICanvas").GetComponent<GameUIController>();
gameUI.ResetInstrumentUI();
audioSource = this.gameObject.GetComponent<AudioSource>();
audioSource.clip = footstepSound;
@ -235,8 +237,8 @@ public class PlayerBehavior : MonoBehaviour
// destroy all tambourines
GameObject[] currentTambourines = GameObject.FindGameObjectsWithTag("tambourine");
foreach (GameObject tambourine in currentTambourines) {
// tambourine.GetComponent<TambourineBehavior>().DestroySelf();
Destroy(tambourine);
tambourine.GetComponent<TambourineBehavior>().DestroySelf();
// Destroy(tambourine);
}
this.stateController.RespawnPlayer();

View File

@ -38,28 +38,32 @@ public class TambourineBehavior : MonoBehaviour {
// if (Input.GetKeyUp(KeyCode.K)) {
// Destroy(this.gameObject);
// }
if (collidedObject != null && collidedObject.tag != "grappleSurface" && !returnToPlayer) {
rb.constraints = RigidbodyConstraints2D.FreezeAll;
// this.gameObject.transform.position = col.transform.position;
timeLerped += Time.deltaTime;
this.gameObject.transform.position = Vector2.Lerp(this.gameObject.transform.position, collidedObject.transform.position, timeLerped/timeToLerp);
if (this.gameObject.transform.position.x == collidedObject.transform.position.x && this.gameObject.transform.position.y == collidedObject.transform.position.y && !pinned) {
animator.SetBool("pinned", true);
pinned = true;
tambourineHitSound.Play();
} else {
// print("pinned, but not same position: " + this.gameObject.transform.position + " / " + collidedObject.transform.position);
}
} else if (returnToPlayer) {
Destroy(rb);
animator.SetBool("pinned", false);
pinned = false;
if (player == null) {
DestroySelf();
} else {
if (collidedObject != null && collidedObject.tag != "grappleSurface" && !returnToPlayer) {
rb.constraints = RigidbodyConstraints2D.FreezeAll;
// this.gameObject.transform.position = col.transform.position;
timeLerped += Time.deltaTime;
this.gameObject.transform.position = Vector2.Lerp(this.gameObject.transform.position, collidedObject.transform.position, timeLerped/timeToLerp);
if (this.gameObject.transform.position.x == collidedObject.transform.position.x && this.gameObject.transform.position.y == collidedObject.transform.position.y && !pinned) {
animator.SetBool("pinned", true);
pinned = true;
tambourineHitSound.Play();
} else {
// print("pinned, but not same position: " + this.gameObject.transform.position + " / " + collidedObject.transform.position);
}
} else if (returnToPlayer) {
Destroy(rb);
animator.SetBool("pinned", false);
pinned = false;
timeLerped += Time.deltaTime;
this.gameObject.transform.position = Vector2.Lerp(this.gameObject.transform.position, player.transform.position, timeLerped/0.1f);
if (this.gameObject.transform.position.x == player.transform.position.x && this.gameObject.transform.position.y == player.transform.position.y) {
player.GetComponent<PlayerBehavior>().SetHasTambourine(true);
Destroy(this.gameObject);
timeLerped += Time.deltaTime;
this.gameObject.transform.position = Vector2.Lerp(this.gameObject.transform.position, player.transform.position, timeLerped/0.1f);
if (this.gameObject.transform.position.x == player.transform.position.x && this.gameObject.transform.position.y == player.transform.position.y) {
player.GetComponent<PlayerBehavior>().SetHasTambourine(true);
Destroy(this.gameObject);
}
}
}
}
@ -97,14 +101,22 @@ public class TambourineBehavior : MonoBehaviour {
}
public void DestroySelf() {
timeLerped = 0.0f;
returnToPlayer = true;
if (player != null) {
timeLerped = 0.0f;
returnToPlayer = true;
}
if (collidedObject != null && collidedObject.tag == "Enemy") {
collidedObject.GetComponent<EnemyPatrol>().pinned = false;
collidedObject.GetComponent<EnemyPatrol>().TogglePin(false);
} else if (collidedObject != null && collidedObject.tag == "Projectile") {
collidedObject.GetComponent<ProjectileBehavior>().Explode();
}
player.GetComponent<PlayerBehavior>().grapplingGun.ReleaseGrapple();
if (player == null) {
Destroy(this.gameObject);
} else {
player.GetComponent<PlayerBehavior>().grapplingGun.ReleaseGrapple();
}
}
}