Guest User

Control

a guest
Aug 28th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class Control : MonoBehaviour {
  7.     public GameObject Actor;
  8.     public float speed = 10f;
  9.     private Vector3 pos;
  10.     public Material mat;
  11.     private int loopCount = 0;
  12.     public bool onGround = true;
  13.     public float distFromGround = 0.6f;
  14.     public bool isAlive = true;
  15.     public bool Started = false;
  16.     public Animator kamera;
  17.     public GameObject deathsound;
  18.     public GameObject music;
  19.     public AudioSource music2;
  20.     private float t = 0.18f;
  21.     // Use this for initialization
  22.     void Start () {
  23.         loopCount = 0;
  24.         kamera.enabled = false;
  25.         onGround = true;
  26.         isAlive = true;
  27.         Started = false;
  28.     }
  29.    
  30.     // Update is called once per frame
  31.     void Update () {
  32.         if (Input.GetMouseButtonDown(0))
  33.         {
  34.             Started = true;
  35.             music.gameObject.SetActive(true);
  36.         }
  37.         if (Input.GetKeyDown(KeyCode.Space))
  38.         {
  39.             Started = true;
  40.             music.gameObject.SetActive(true);
  41.         }
  42.         if (isAlive == true && Started == true)
  43.         {
  44.             kamera.enabled = true;
  45.             onGround = isGrounded();
  46.             pos = Actor.transform.position;
  47.             Actor.transform.Translate((Vector3.forward * speed) * Time.deltaTime);
  48.             if (onGround == true)
  49.             {
  50.                 GameObject Actor2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  51.                 Actor2.transform.position = pos;
  52.                 Actor2.GetComponent<MeshRenderer>().material = mat;
  53.                 Actor2.GetComponent<BoxCollider>().isTrigger = true;
  54.                 if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
  55.                 {
  56.                     if (loopCount % 2 != 0)
  57.                     {
  58.                         Actor.transform.eulerAngles = new Vector3 (0, 90, 0);
  59.                         loopCount++;
  60.                     }
  61.                     else
  62.                     {
  63.                         Actor.transform.eulerAngles = new Vector3 (0, 0, 0);
  64.                         loopCount++;
  65.                     }
  66.                 }
  67.             }
  68.         }
  69.         if (isAlive == false)
  70.         {
  71.             music2.volume -= t * Time.deltaTime;
  72.         }
  73.     }
  74.     public bool isGrounded()
  75.     {
  76.         return Physics.Raycast(Actor.transform.position, Vector3.down, distFromGround);
  77.     }
  78.     private void OnCollisionEnter (Collision collision)
  79.     {
  80.         if (collision.gameObject.tag == "obstacle")
  81.         {
  82.             isAlive = false;
  83.             Started = false;
  84.             deathsound.gameObject.SetActive(true);
  85.             kamera.enabled = false;
  86.             GameObject Prime = GameObject.CreatePrimitive(PrimitiveType.Cube);
  87.             GameObject Prime1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  88.             GameObject Prime2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
  89.             Prime.transform.position = pos;
  90.             Prime1.transform.position = pos;
  91.             Prime2.transform.position = pos;
  92.             Prime.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
  93.             Prime1.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
  94.             Prime2.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
  95.             Prime.GetComponent<MeshRenderer>().material = mat;
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment