Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpikesFalling : MonoBehaviour
- {
- [SerializeField] float timeForFalling;
- [SerializeField] Animator myAnimator;
- [SerializeField] Rigidbody2D spikesFallingRigidBody;
- private void OnTriggerEnter2D(Collider2D other)
- {
- if(other.gameObject.tag == "Player")
- {
- myAnimator.SetBool("isPlayerNear", true);
- StartCoroutine(ShakingAnimation());
- }
- }
- IEnumerator ShakingAnimation()
- {
- yield return new WaitForSeconds(timeForFalling);
- myAnimator.enabled = false;
- GetComponent<CircleCollider2D>().enabled = false;
- }
- // Start is called before the first frame update
- void Start()
- {
- spikesFallingRigidBody = GetComponent<Rigidbody2D>();
- myAnimator = GetComponent<Animator>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement