add player death animation
also bugfixed some tambourine stuff
This commit is contained in:
		@@ -27,6 +27,7 @@ public class PlayerBehavior : MonoBehaviour
 | 
			
		||||
    [SerializeField] private StateController stateController;
 | 
			
		||||
 | 
			
		||||
    Animator animator;
 | 
			
		||||
    [HideInInspector] public bool playerIsAlive = true;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    void Start()
 | 
			
		||||
@@ -35,32 +36,34 @@ public class PlayerBehavior : MonoBehaviour
 | 
			
		||||
        stateController = GameObject.Find("StateController").GetComponent<StateController>();
 | 
			
		||||
        animator = GetComponent<Animator>();
 | 
			
		||||
        GameObject.Find("Main Camera").GetComponent<CameraMovement>().player = this.gameObject;
 | 
			
		||||
        playerIsAlive = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void Update()
 | 
			
		||||
    {
 | 
			
		||||
        if (playerIsAlive) {
 | 
			
		||||
            // throw tambourine
 | 
			
		||||
            // if (Input.GetKeyDown(KeyCode.K)) {
 | 
			
		||||
            if (playerInput.actions["ThrowTambourine"].WasPressedThisFrame())
 | 
			
		||||
            {
 | 
			
		||||
                ThrowTambourine();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        // throw tambourine
 | 
			
		||||
        // if (Input.GetKeyDown(KeyCode.K)) {
 | 
			
		||||
        if (playerInput.actions["ThrowTambourine"].WasPressedThisFrame())
 | 
			
		||||
        {
 | 
			
		||||
            ThrowTambourine();
 | 
			
		||||
        }
 | 
			
		||||
            // grapple
 | 
			
		||||
            tambourine = GameObject.FindGameObjectWithTag("tambourine");
 | 
			
		||||
            // if (Input.GetKeyDown(KeyCode.L)) {
 | 
			
		||||
            if (playerInput.actions["Grapple"].WasPressedThisFrame())
 | 
			
		||||
            {
 | 
			
		||||
                AttemptGrapple();
 | 
			
		||||
            }
 | 
			
		||||
            // if (Input.GetKeyUp(KeyCode.L)) {
 | 
			
		||||
            if (playerInput.actions["Grapple"].WasReleasedThisFrame())
 | 
			
		||||
            {
 | 
			
		||||
                LetGoOfGrapple();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        // grapple
 | 
			
		||||
        tambourine = GameObject.FindGameObjectWithTag("tambourine");
 | 
			
		||||
        // if (Input.GetKeyDown(KeyCode.L)) {
 | 
			
		||||
        if (playerInput.actions["Grapple"].WasPressedThisFrame())
 | 
			
		||||
        {
 | 
			
		||||
            AttemptGrapple();
 | 
			
		||||
            Animate();
 | 
			
		||||
        }
 | 
			
		||||
        // if (Input.GetKeyUp(KeyCode.L)) {
 | 
			
		||||
        if (playerInput.actions["Grapple"].WasReleasedThisFrame())
 | 
			
		||||
        {
 | 
			
		||||
            LetGoOfGrapple();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Animate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void Animate() {
 | 
			
		||||
@@ -76,20 +79,22 @@ public class PlayerBehavior : MonoBehaviour
 | 
			
		||||
 | 
			
		||||
    void OnMove(InputValue value)
 | 
			
		||||
    {
 | 
			
		||||
        _hInput = value.Get<Vector2>().x;
 | 
			
		||||
        if (_hInput < 0)
 | 
			
		||||
        {
 | 
			
		||||
            if (forward != -1) { // if character hasnt already flipped 
 | 
			
		||||
                FlipRenderer();
 | 
			
		||||
        if (playerIsAlive) {
 | 
			
		||||
            _hInput = value.Get<Vector2>().x;
 | 
			
		||||
            if (_hInput < 0)
 | 
			
		||||
            {
 | 
			
		||||
                if (forward != -1) { // if character hasnt already flipped 
 | 
			
		||||
                    FlipRenderer();
 | 
			
		||||
                }
 | 
			
		||||
                forward = -1;
 | 
			
		||||
            }
 | 
			
		||||
            forward = -1;
 | 
			
		||||
        }
 | 
			
		||||
        else if (_hInput > 0)
 | 
			
		||||
        {
 | 
			
		||||
            if (forward != 1) { // if character hasnt already flipped 
 | 
			
		||||
                FlipRenderer();
 | 
			
		||||
            else if (_hInput > 0)
 | 
			
		||||
            {
 | 
			
		||||
                if (forward != 1) { // if character hasnt already flipped 
 | 
			
		||||
                    FlipRenderer();
 | 
			
		||||
                }
 | 
			
		||||
                forward = 1;
 | 
			
		||||
            }
 | 
			
		||||
            forward = 1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
@@ -150,7 +155,7 @@ public class PlayerBehavior : MonoBehaviour
 | 
			
		||||
        }
 | 
			
		||||
        else if (col.tag == "instaDeath")
 | 
			
		||||
        {
 | 
			
		||||
            DestroyPlayer();
 | 
			
		||||
            StartCoroutine(DestroyPlayer());
 | 
			
		||||
        }
 | 
			
		||||
        else if (col.tag == "spawnPoint") {
 | 
			
		||||
            stateController.spawnPoint.GetComponent<SpawnPointBehavior>().DeactivateSpawnPoint();
 | 
			
		||||
@@ -182,16 +187,22 @@ public class PlayerBehavior : MonoBehaviour
 | 
			
		||||
                _rb.AddForce(Vector2.up * 8, ForceMode2D.Impulse);
 | 
			
		||||
                collision.gameObject.GetComponent<EnemyPatrol>().DefeatEnemy();
 | 
			
		||||
            } else {
 | 
			
		||||
                DestroyPlayer();
 | 
			
		||||
                StartCoroutine(DestroyPlayer());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else if (collision.gameObject.tag == "Projectile") {
 | 
			
		||||
            Destroy(collision.gameObject);
 | 
			
		||||
            DestroyPlayer();
 | 
			
		||||
            StartCoroutine(DestroyPlayer());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void DestroyPlayer() {
 | 
			
		||||
    IEnumerator DestroyPlayer() {
 | 
			
		||||
        playerIsAlive = false;
 | 
			
		||||
 | 
			
		||||
        // animate
 | 
			
		||||
        animator.Play("Die");
 | 
			
		||||
        yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
 | 
			
		||||
 | 
			
		||||
        this.stateController.SetDeathCanvasActive(true);
 | 
			
		||||
 | 
			
		||||
        // destroy all tambourines
 | 
			
		||||
@@ -200,6 +211,7 @@ public class PlayerBehavior : MonoBehaviour
 | 
			
		||||
            tambourine.GetComponent<TambourineBehavior>().DestroySelf();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        yield return new WaitForSeconds(2f);
 | 
			
		||||
        Destroy(this.gameObject);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -58,12 +58,16 @@ public class PlayerMovement : MonoBehaviour
 | 
			
		||||
 | 
			
		||||
    [Header("Layers & Tags")]
 | 
			
		||||
    [SerializeField] private LayerMask _groundLayer;
 | 
			
		||||
 | 
			
		||||
    [HideInInspector] private PlayerBehavior playerBehavior;
 | 
			
		||||
    #endregion
 | 
			
		||||
 | 
			
		||||
    private void Awake()
 | 
			
		||||
    {
 | 
			
		||||
        RB = GetComponent<Rigidbody2D>();
 | 
			
		||||
        grapplingRope = this.gameObject.GetComponent<PlayerBehavior>().grapplingRope;
 | 
			
		||||
        playerBehavior = this.gameObject.GetComponent<PlayerBehavior>();
 | 
			
		||||
        grapplingRope = playerBehavior.grapplingRope;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void Start()
 | 
			
		||||
@@ -74,12 +78,16 @@ public class PlayerMovement : MonoBehaviour
 | 
			
		||||
 | 
			
		||||
    void OnMove(InputValue value)
 | 
			
		||||
    {
 | 
			
		||||
        this._moveInput = value.Get<Vector2>();
 | 
			
		||||
        if (playerBehavior.playerIsAlive) {
 | 
			
		||||
            this._moveInput = value.Get<Vector2>();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void OnJump()
 | 
			
		||||
    {
 | 
			
		||||
        OnJumpInput();
 | 
			
		||||
        if (playerBehavior.playerIsAlive) {
 | 
			
		||||
            OnJumpInput();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void Update()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user