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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user