Shamba

CubeMovement(updated)

Mar 12th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.28 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class CubeMovement : MonoBehaviour {
  7.     public GameObject Actor;
  8.     public float speed = 1;
  9.     private Vector3 pos;
  10.     public Material mat;
  11.     public static int loopCount = 0;
  12.     public bool onGround = true;
  13.     public float distFromGround = 0.6f;
  14.     public bool isAlive = true;
  15.     public GameObject StartText;
  16.     public GameObject RestartText;
  17.     public GameObject Restartbutton;
  18.     public bool Started = false;
  19.     public GameObject music;
  20.     public static bool uturn = false;
  21.     public static int control_type = 1;
  22.     // Use this for initialization
  23.     void Start ()
  24.     {
  25.        loopCount = 0;
  26.        onGround = true;
  27.        isAlive = true;
  28.        Started = false;
  29.     }
  30.    
  31.     // Update is called once per frame
  32.     void Update () {
  33.         if(Input.GetMouseButtonDown(0))
  34.         {
  35.             StartText.gameObject.SetActive(false);
  36.             Started = true;
  37.             music.gameObject.SetActive(true);
  38.         }
  39.         if (isAlive == true && Started == true)
  40.         {
  41.          
  42.             onGround = isGrounded();
  43.             pos = Actor.transform.position;
  44.             Actor.transform.Translate(Vector3.forward * speed );
  45.             if (onGround == true)
  46.             {
  47.                 GameObject Actor2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  48.                 Actor2.transform.position = pos;
  49.                 Actor2.GetComponent<MeshRenderer>().material = mat;
  50.                 Actor2.GetComponent<BoxCollider>().isTrigger = true;
  51.                 if (Input.GetMouseButtonDown(0))
  52.                 {
  53.                     if (control_type == 1)
  54.                     {
  55.                         if (loopCount % 2 != 0)
  56.                         {
  57.                             Actor.transform.eulerAngles = new Vector3(0, 90, 0);
  58.                             loopCount++;
  59.                         }
  60.                         else
  61.                         {
  62.                             Actor.transform.eulerAngles = new Vector3(0, 0, 0);
  63.                             loopCount++;
  64.                         }
  65.                     }
  66.                     else if(control_type ==2)
  67.                     {
  68.                         if (loopCount % 2 != 0)
  69.                         {
  70.                             Actor.transform.eulerAngles = new Vector3(0, 90, 0);
  71.                             loopCount++;
  72.                         }
  73.                         else
  74.                         {
  75.                             Actor.transform.eulerAngles = new Vector3(0, 180, 0);
  76.                             loopCount++;
  77.                         }
  78.                     }
  79.                     if (control_type == 3)
  80.                     {
  81.                         if (loopCount % 2 != 0)
  82.                         {
  83.                             Actor.transform.eulerAngles = new Vector3(0, 180, 0);
  84.                             loopCount++;
  85.                         }
  86.                         else
  87.                         {
  88.                             Actor.transform.eulerAngles = new Vector3(0, 270, 0);
  89.                             loopCount++;
  90.                         }
  91.                     }
  92.                     if (control_type == 4)
  93.                     {
  94.                         if (loopCount % 2 != 0)
  95.                         {
  96.                             Actor.transform.eulerAngles = new Vector3(0, 270, 0);
  97.                             loopCount++;
  98.                         }
  99.                         else
  100.                         {
  101.                             Actor.transform.eulerAngles = new Vector3(0, 0, 0);
  102.                             loopCount++;
  103.                         }
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.     }
  109.     public bool isGrounded()
  110.     {
  111.         return Physics.Raycast(Actor.transform.position, Vector3.down, distFromGround);
  112.     }
  113.     private void OnCollisionEnter(Collision collision)
  114.     {
  115.         if (collision.gameObject.tag == "obstacle")
  116.         {
  117.             isAlive = false;
  118.             Started = false;
  119.             music.gameObject.SetActive(false);
  120.             GameObject Prime =   GameObject.CreatePrimitive(PrimitiveType.Cube);
  121.             GameObject Prime1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  122.             GameObject Prime2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  123.             Prime.transform.position = pos;
  124.             Prime1.transform.position = pos;
  125.             Prime2.transform.position = pos;
  126.             Prime.AddComponent<Rigidbody>().velocity=Random.onUnitSphere*50;
  127.             Prime1.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
  128.             Prime2.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 100;
  129.             Prime.GetComponent<MeshRenderer>().material = mat;
  130.             Prime1.GetComponent<MeshRenderer>().material = mat;
  131.             Prime2.GetComponent<MeshRenderer>().material = mat;
  132.             RestartText.gameObject.SetActive(true);
  133.             Restartbutton.gameObject.SetActive(true);
  134.  
  135.  
  136.  
  137.         }
  138.        
  139.     }
  140.     public void Restart()
  141.     {
  142.         SceneManager.LoadScene(0);
  143.     }
  144. }
  145.  
  146. using System.Collections;
  147. using System.Collections.Generic;
  148. using UnityEngine;
  149. using UnityEngine.SceneManagement;
  150.  
  151. public class CubeMovement : MonoBehaviour {
  152.     public GameObject Actor;
  153.     public float speed = 1;
  154.     private Vector3 pos;
  155.     public Material mat;
  156.     public static int loopCount = 0;
  157.     public bool onGround = true;
  158.     public float distFromGround = 0.6f;
  159.     public bool isAlive = true;
  160.     public GameObject StartText;
  161.     public GameObject RestartText;
  162.     public GameObject Restartbutton;
  163.     public bool Started = false;
  164.     public GameObject music;
  165.     public static bool uturn = false;
  166.     public static int control_type = 1;
  167.     // Use this for initialization
  168.     void Start ()
  169.     {
  170.        loopCount = 0;
  171.        onGround = true;
  172.        isAlive = true;
  173.        Started = false;
  174.     }
  175.    
  176.     // Update is called once per frame
  177.     void Update () {
  178.         if(Input.GetMouseButtonDown(0))
  179.         {
  180.             StartText.gameObject.SetActive(false);
  181.             Started = true;
  182.             music.gameObject.SetActive(true);
  183.         }
  184.         if (isAlive == true && Started == true)
  185.         {
  186.          
  187.             onGround = isGrounded();
  188.             pos = Actor.transform.position;
  189.             Actor.transform.Translate(Vector3.forward * speed );
  190.             if (onGround == true)
  191.             {
  192.                 GameObject Actor2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  193.                 Actor2.transform.position = pos;
  194.                 Actor2.GetComponent<MeshRenderer>().material = mat;
  195.                 Actor2.GetComponent<BoxCollider>().isTrigger = true;
  196.                 if (Input.GetMouseButtonDown(0))
  197.                 {
  198.                     if (control_type == 1)
  199.                     {
  200.                         if (loopCount % 2 != 0)
  201.                         {
  202.                             Actor.transform.eulerAngles = new Vector3(0, 90, 0);
  203.                             loopCount++;
  204.                         }
  205.                         else
  206.                         {
  207.                             Actor.transform.eulerAngles = new Vector3(0, 0, 0);
  208.                             loopCount++;
  209.                         }
  210.                     }
  211.                     else if(control_type ==2)
  212.                     {
  213.                         if (loopCount % 2 != 0)
  214.                         {
  215.                             Actor.transform.eulerAngles = new Vector3(0, 90, 0);
  216.                             loopCount++;
  217.                         }
  218.                         else
  219.                         {
  220.                             Actor.transform.eulerAngles = new Vector3(0, 180, 0);
  221.                             loopCount++;
  222.                         }
  223.                     }
  224.                     if (control_type == 3)
  225.                     {
  226.                         if (loopCount % 2 != 0)
  227.                         {
  228.                             Actor.transform.eulerAngles = new Vector3(0, 180, 0);
  229.                             loopCount++;
  230.                         }
  231.                         else
  232.                         {
  233.                             Actor.transform.eulerAngles = new Vector3(0, 270, 0);
  234.                             loopCount++;
  235.                         }
  236.                     }
  237.                     if (control_type == 4)
  238.                     {
  239.                         if (loopCount % 2 != 0)
  240.                         {
  241.                             Actor.transform.eulerAngles = new Vector3(0, 270, 0);
  242.                             loopCount++;
  243.                         }
  244.                         else
  245.                         {
  246.                             Actor.transform.eulerAngles = new Vector3(0, 0, 0);
  247.                             loopCount++;
  248.                         }
  249.                     }
  250.                 }
  251.             }
  252.         }
  253.     }
  254.     public bool isGrounded()
  255.     {
  256.         return Physics.Raycast(Actor.transform.position, Vector3.down, distFromGround);
  257.     }
  258.     private void OnCollisionEnter(Collision collision)
  259.     {
  260.         if (collision.gameObject.tag == "obstacle")
  261.         {
  262.             isAlive = false;
  263.             Started = false;
  264.             music.gameObject.SetActive(false);
  265.             GameObject Prime =   GameObject.CreatePrimitive(PrimitiveType.Cube);
  266.             GameObject Prime1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  267.             GameObject Prime2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  268.             Prime.transform.position = pos;
  269.             Prime1.transform.position = pos;
  270.             Prime2.transform.position = pos;
  271.             Prime.AddComponent<Rigidbody>().velocity=Random.onUnitSphere*50;
  272.             Prime1.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
  273.             Prime2.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 100;
  274.             Prime.GetComponent<MeshRenderer>().material = mat;
  275.             Prime1.GetComponent<MeshRenderer>().material = mat;
  276.             Prime2.GetComponent<MeshRenderer>().material = mat;
  277.             RestartText.gameObject.SetActive(true);
  278.             Restartbutton.gameObject.SetActive(true);
  279.  
  280.  
  281.  
  282.         }
  283.        
  284.     }
  285.     public void Restart()
  286.     {
  287.         SceneManager.LoadScene(0);
  288.     }
  289. }
Add Comment
Please, Sign In to add comment