Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. seperateRooms()
  2. {
  3.     // this adds the temporary rigidbody
  4.     foreach (GameObject room in rooms)
  5.     {
  6.         room.AddComponent<Rigidbody>();
  7.         room.GetComponent<Rigidbody>().isKinematic = true;
  8.         room.GetComponent<Rigidbody>().useGravity = false;
  9.     }
  10.  
  11.      for(int i = rooms.Count-1; i > 0; i--)
  12.      {
  13.         GameObject room = (GameObject)rooms[i];
  14.         Rigidbody rb = room.GetComponent<Rigidbody>();
  15.         rb.isKinematic = false;
  16.         rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY;
  17.  
  18.         while (!(rb.IsSleeping()))
  19.         {
  20.             rb.MovePosition(room.transform.position + room.transform.forward * Time.deltaTime);
  21.         }
  22.  
  23.         rb.isKinematic = true;
  24.     }
  25.  
  26.     foreach (GameObject room in rooms)
  27.     {
  28.         Destroy(room.GetComponent<Rigidbody>());
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement