Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3.  
  4. namespace Rush {
  5.  
  6.     /// <summary>
  7.     ///
  8.     /// </summary>
  9.     public class Cube : MonoBehaviour {
  10.         Vector3 vectorDir;
  11.         Vector3 axis;
  12.         Vector3 left = Vector3.left;
  13.         Vector3[] directionArray = new[] { Vector3.left , Vector3.forward, Vector3.right, Vector3.back };
  14.         Vector3[] rotationArray = new[] { Vector3.forward , Vector3.right, Vector3.back, Vector3.left };
  15.  
  16.  
  17.      
  18.  
  19.         protected void Start() {
  20.             axis = Vector3.forward;
  21.             StartCoroutine(RotateCoroutine());
  22.             Debug.Log(axis);
  23.             Debug.Log(vectorDir);
  24.         }
  25.  
  26.         protected void Update() {
  27.            
  28.            
  29.         }
  30.  
  31.  
  32.         IEnumerator RotateCoroutine() {
  33.             while (true) {
  34.                
  35.                 vectorDir = transform.position;
  36.                 vectorDir += left * 0.5f; // half a cube width toward destination
  37.                 vectorDir -= Vector3.up * 0.5f;  // subtract half cube width from y for the floor
  38.                
  39.                 int frames = 30;  
  40.                                  
  41.                 float degreesPerFrame = 90 / (float)frames;
  42.                 for (int i = 1; i <= frames; i++) {
  43.                     transform.RotateAround(vectorDir, axis, degreesPerFrame);
  44.                     yield return new WaitForFixedUpdate();
  45.                    
  46.                 }
  47.             }
  48.  
  49.         }
  50.  
  51.  
  52.         //void FixedUpdate() {
  53.         //    Vector3 fwd = transform.TransformDirection(Vector3.forward);
  54.  
  55.         //    if (Physics.Raycast(transform.position, fwd, 10))
  56.         //        print("There is something in front of the object!");
  57.         //}
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.        
  65.         protected void OnCollisionEnter(Collision collision) {
  66.             int indice = 0;
  67.             if (collision.gameObject.tag == "mur") { // if the hit object's name is room...
  68.                 indice++;
  69.                 if (indice >= directionArray.Length) indice = 0;
  70.                 axis = rotationArray[indice];
  71.                 vectorDir = directionArray[indice];
  72.                
  73.                 Debug.Log(indice);
  74.                 Debug.Log(axis);
  75.                 Debug.Log(vectorDir);
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement