fixed: tambourine ui resets properly on player death
This commit is contained in:
		@@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user