49 lines
1.0 KiB
C#
49 lines
1.0 KiB
C#
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;
|
|
}
|
|
}
|
|
} |