Advertisement
Guest User

spikes falling

a guest
Aug 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public class SpikesFalling : MonoBehaviour
  2. {
  3. [SerializeField] float timeForFalling;
  4. [SerializeField] Animator myAnimator;
  5. [SerializeField] Rigidbody2D spikesFallingRigidBody;
  6.  
  7. private void OnTriggerEnter2D(Collider2D other)
  8. {
  9. if(other.gameObject.tag == "Player")
  10. {
  11. myAnimator.SetBool("isPlayerNear", true);
  12. StartCoroutine(ShakingAnimation());
  13.  
  14. }
  15. }
  16.  
  17. IEnumerator ShakingAnimation()
  18. {
  19. yield return new WaitForSeconds(timeForFalling);
  20. myAnimator.enabled = false;
  21. GetComponent<CircleCollider2D>().enabled = false;
  22. }
  23.  
  24. // Start is called before the first frame update
  25. void Start()
  26. {
  27. spikesFallingRigidBody = GetComponent<Rigidbody2D>();
  28. myAnimator = GetComponent<Animator>();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement