CakeMeister

Falling Plat

Jun 26th, 2017
1,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class fallingPlat : MonoBehaviour {
  6.     public Rigidbody2D r2;
  7.     public float timedelay = 2;
  8.     // Use this for initialization
  9.     void Start () {
  10.         r2 = gameObject.GetComponent<Rigidbody2D>();
  11.     }
  12.  
  13.  
  14.     private void OnCollisionEnter2D(Collision2D col)
  15.     {
  16.         if (col.collider.CompareTag("Player"))
  17.         {
  18.             StartCoroutine(fall());
  19.         }
  20.     }
  21.  
  22.     IEnumerator fall()
  23.     {
  24.         yield return new WaitForSeconds(timedelay);
  25.         r2.bodyType = RigidbodyType2D.Dynamic;
  26.         yield return 0;
  27.     }
  28. }
Add Comment
Please, Sign In to add comment