Advertisement
Guest User

Cheese (1HGJ170) Source Code

a guest
Jul 28th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. /* BEGIN SCRIPT "PlayerMovement.cs" */
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class PlayerMovement : MonoBehaviour {
  7.  
  8.     public float acceleration = 1f;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.        
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.         if (Input.GetKey (KeyCode.W)) {
  18.             this.GetComponent<Rigidbody> ().AddForce (new Vector3 (0, 0, acceleration));
  19.         }
  20.         if (Input.GetKey (KeyCode.S)) {
  21.             this.GetComponent<Rigidbody> ().AddForce (new Vector3 (0, 0, -acceleration));
  22.         }
  23.         if (Input.GetKey (KeyCode.D)) {
  24.             this.GetComponent<Rigidbody> ().AddForce (new Vector3 (acceleration, 0, 0));
  25.         }
  26.         if (Input.GetKey (KeyCode.A)) {
  27.             this.GetComponent<Rigidbody> ().AddForce (new Vector3 (-acceleration, 0, 0));
  28.         }
  29.  
  30.         gameObject.transform.rotation = new Quaternion (gameObject.transform.rotation.x + 1, 0, 0, 0);
  31.     }
  32. }
  33. /* END SCRIPT */
  34. /* BEGIN SCRIPT "MatchPlayer.cs" */
  35. using System.Collections;
  36. using System.Collections.Generic;
  37. using UnityEngine;
  38.  
  39. public class MatchPlayer : MonoBehaviour {
  40.  
  41.     public GameObject player;
  42.     public Vector3 defaultPos = new Vector3(-18, 20, -18);
  43.  
  44.     // Use this for initialization
  45.     void Start () {
  46.        
  47.     }
  48.    
  49.     // Update is called once per frame
  50.     void Update () {
  51.         gameObject.transform.position = player.transform.position + defaultPos;
  52.     }
  53. }
  54. /* END SCRIPT */
  55. /* BEGIN SCRIPT "Cheese.cs" */
  56. using System.Collections;
  57. using System.Collections.Generic;
  58. using UnityEngine;
  59. using UnityEngine.UI;
  60.  
  61. public class Cheese : MonoBehaviour {
  62.  
  63.     public Text scoreboard;
  64.     private int score = 0;
  65.     private bool started = false;
  66.     private int time = 5;
  67.  
  68.     private Vector3[] locations = {
  69.         new Vector3(7.5f,0f,7.5f), new Vector3(7.5f,0f,-7.5f), new Vector3(-7.5f,0f,7.5f), new Vector3(-7.5f,0f,-7.5f), new Vector3(0f,0f,0f), new Vector3(7.5f,0f,0f), new Vector3(-7.5f,0f,0f), new Vector3(0f,0f,7.5f), new Vector3(0f,0f,-7.5f)
  70.     };
  71.  
  72.     private Vector3 last = new Vector3(-7.5f,0f,7.5f);
  73.  
  74.     // Use this for initialization
  75.     void Start () {
  76.        
  77.     }
  78.    
  79.     // Update is called once per frame
  80.     void Update () {
  81.  
  82.     }
  83.  
  84.     void IGUpdate(){
  85.         time--;
  86.         scoreboard.text = "Time: " + time + "\n" + "Score: " + score;
  87.  
  88.         if (time <= 0) {
  89.             scoreboard.text = "You lose.";
  90.             Invoke("Close",3f);
  91.         }
  92.     }
  93.  
  94.     void Close(){
  95.         Debug.Log ("Quit");
  96.         Application.Quit ();
  97.     }
  98.  
  99.     void OnTriggerEnter(){
  100.         if (!started) {
  101.             InvokeRepeating ("IGUpdate", 0f, 1f);
  102.             started = true;
  103.         }
  104.        
  105.         score++;
  106.         time = 6;
  107.  
  108.         Vector3 newLocation = new Vector3(0, 0, 0);
  109.         bool goodLocation = false;
  110.         int safety = 0;
  111.         while (!goodLocation && (safety < 100)) {
  112.             newLocation = locations [Random.Range (0, 9)];
  113.             if (newLocation != last) {
  114.                 goodLocation = true;
  115.             }
  116.         }
  117.  
  118.         transform.position = newLocation;
  119.         last = newLocation;
  120.     }
  121. }
  122. /* END SCRIPT */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement