Keep Away logic finalized and UI polished up

One animation bug found when player picks up hat (possibly when jumping)
This commit is contained in:
djkellerman
2025-03-28 22:50:33 -04:00
parent 2913d4b927
commit c7b1e55a3e
8 changed files with 478 additions and 30 deletions

View File

@@ -96,12 +96,17 @@ public class Damageable : MonoBehaviour
{
if (GameManager.Instance != null)
{
GetComponent<UseItem>().DropItem();
UseItem useItem = GetComponent<UseItem>();
if (useItem != null)
{
useItem.DropItem(); // Ensure the player drops the item before the death animation
}
animator.SetBool("die", true);
dying = true;
}
}
public void HandleDeath() // Removes player from dying state after respawn
{
GameManager.Instance.PlayerDied(this);

View File

@@ -7,6 +7,12 @@ public class UseItem : MonoBehaviour
private bool isHoldingItem = false;
private float holdStartTime;
public float holdTime;
private Damageable damageable;
private void Start()
{
damageable = GetComponent<Damageable>();
}
void Update()
{
@@ -25,7 +31,7 @@ public class UseItem : MonoBehaviour
private void OnCollisionEnter2D(Collision2D collision) // Player automatically picks up hat when touching it
{
if (collision.gameObject.CompareTag("Hat") && !isHoldingItem)
if (collision.gameObject.CompareTag("Hat") && !isHoldingItem && !damageable.dying)
{
PickUpItem(collision.gameObject);
}
@@ -33,12 +39,15 @@ public class UseItem : MonoBehaviour
private void PickUpItem(GameObject item) // Player picks up hat and starts hold counter
{
if (damageable.dying) return; // Prevent picking up items if the player is dying
heldItem = item;
isHoldingItem = true;
holdStartTime = Time.time;
item.GetComponent<Collider2D>().enabled = false;
item.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
item.transform.rotation = Quaternion.identity;
item.GetComponent<HatRespawn>().Interact();
if (!GameManager.playerHoldTimes.ContainsKey(gameObject))
{
GameManager.playerHoldTimes[gameObject] = 0f;