Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- namespace Rush {
- /// <summary>
- ///
- /// </summary>
- public class Cube : MonoBehaviour {
- Vector3 vectorDir;
- Vector3 axis;
- Vector3 left = Vector3.left;
- Vector3[] directionArray = new[] { Vector3.left , Vector3.forward, Vector3.right, Vector3.back };
- Vector3[] rotationArray = new[] { Vector3.forward , Vector3.right, Vector3.back, Vector3.left };
- protected void Start() {
- axis = Vector3.forward;
- StartCoroutine(RotateCoroutine());
- Debug.Log(axis);
- Debug.Log(vectorDir);
- }
- protected void Update() {
- }
- IEnumerator RotateCoroutine() {
- while (true) {
- vectorDir = transform.position;
- vectorDir += left * 0.5f; // half a cube width toward destination
- vectorDir -= Vector3.up * 0.5f; // subtract half cube width from y for the floor
- int frames = 30;
- float degreesPerFrame = 90 / (float)frames;
- for (int i = 1; i <= frames; i++) {
- transform.RotateAround(vectorDir, axis, degreesPerFrame);
- yield return new WaitForFixedUpdate();
- }
- }
- }
- //void FixedUpdate() {
- // Vector3 fwd = transform.TransformDirection(Vector3.forward);
- // if (Physics.Raycast(transform.position, fwd, 10))
- // print("There is something in front of the object!");
- //}
- protected void OnCollisionEnter(Collision collision) {
- int indice = 0;
- if (collision.gameObject.tag == "mur") { // if the hit object's name is room...
- indice++;
- if (indice >= directionArray.Length) indice = 0;
- axis = rotationArray[indice];
- vectorDir = directionArray[indice];
- Debug.Log(indice);
- Debug.Log(axis);
- Debug.Log(vectorDir);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement