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;
|
2023-06-24 14:22:30 +02:00
|
|
|
public AudioSource audioSource; // Reference to the AudioSource component
|
|
|
|
public AudioClip pushSound; // The sound clip to be played
|
|
|
|
public bool isPlaying = false; // Boolean to control the sound loop
|
2023-06-17 17:27:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
animator = GetComponent<Animator>();
|
|
|
|
rb = GetComponent<Rigidbody2D>();
|
|
|
|
isColliding = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (isColliding && rb.velocity.magnitude > 0.1f)
|
|
|
|
{
|
|
|
|
animator.SetBool("IsPushing", true);
|
2023-06-24 14:22:30 +02:00
|
|
|
|
|
|
|
if(!isPlaying){
|
|
|
|
audioSource.clip = pushSound;
|
|
|
|
audioSource.loop = true;
|
|
|
|
audioSource.Play();
|
|
|
|
isPlaying = true;}
|
|
|
|
|
2023-06-17 17:27:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
animator.SetBool("IsPushing", false);
|
2023-06-24 14:22:30 +02:00
|
|
|
audioSource.Stop();
|
|
|
|
isPlaying = false;
|
2023-06-17 17:27:06 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|