49 lines
1.0 KiB
C#
Raw Normal View History

2023-06-17 17:27:06 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class IsPushingTester: MonoBehaviour
{
private Animator animator;
private Rigidbody2D rb;
private bool isColliding;
void Start()
{
animator = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
isColliding = false;
}
void Update()
{
if (isColliding && rb.velocity.magnitude > 0.1f)
{
animator.SetBool("IsPushing", true);
}
else
{
animator.SetBool("IsPushing", false);
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("PressurePlatable") && collision.collider is EdgeCollider2D)
{
isColliding = true;
}
}
void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("PressurePlatable") && collision.collider is EdgeCollider2D)
{
isColliding = false;
}
}
}