Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class Control : MonoBehaviour {
- public GameObject Actor;
- public float speed = 10f;
- private Vector3 pos;
- public Material mat;
- private int loopCount = 0;
- public bool onGround = true;
- public float distFromGround = 0.6f;
- public bool isAlive = true;
- public bool Started = false;
- public Animator kamera;
- public GameObject deathsound;
- public GameObject music;
- public AudioSource music2;
- private float t = 0.18f;
- // Use this for initialization
- void Start () {
- loopCount = 0;
- kamera.enabled = false;
- onGround = true;
- isAlive = true;
- Started = false;
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetMouseButtonDown(0))
- {
- Started = true;
- music.gameObject.SetActive(true);
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- Started = true;
- music.gameObject.SetActive(true);
- }
- if (isAlive == true && Started == true)
- {
- kamera.enabled = true;
- onGround = isGrounded();
- pos = Actor.transform.position;
- Actor.transform.Translate((Vector3.forward * speed) * Time.deltaTime);
- if (onGround == true)
- {
- GameObject Actor2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
- Actor2.transform.position = pos;
- Actor2.GetComponent<MeshRenderer>().material = mat;
- Actor2.GetComponent<BoxCollider>().isTrigger = true;
- if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
- {
- if (loopCount % 2 != 0)
- {
- Actor.transform.eulerAngles = new Vector3 (0, 90, 0);
- loopCount++;
- }
- else
- {
- Actor.transform.eulerAngles = new Vector3 (0, 0, 0);
- loopCount++;
- }
- }
- }
- }
- if (isAlive == false)
- {
- music2.volume -= t * Time.deltaTime;
- }
- }
- public bool isGrounded()
- {
- return Physics.Raycast(Actor.transform.position, Vector3.down, distFromGround);
- }
- private void OnCollisionEnter (Collision collision)
- {
- if (collision.gameObject.tag == "obstacle")
- {
- isAlive = false;
- Started = false;
- deathsound.gameObject.SetActive(true);
- kamera.enabled = false;
- GameObject Prime = GameObject.CreatePrimitive(PrimitiveType.Cube);
- GameObject Prime1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
- GameObject Prime2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
- Prime.transform.position = pos;
- Prime1.transform.position = pos;
- Prime2.transform.position = pos;
- Prime.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
- Prime1.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
- Prime2.AddComponent<Rigidbody>().velocity = Random.onUnitSphere * 50;
- Prime.GetComponent<MeshRenderer>().material = mat;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment