Advertisement
ostyleo

Untitled

Mar 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;
  5.  
  6. public class GameManager : MonoBehaviour {
  7.  
  8.     int selectedZombiePosition = 0;
  9.     public GameObject selectedZombie;
  10.     public List<GameObject> zombies;
  11.     public Vector3 selectedSize;
  12.     public Vector3 defaultSize;
  13.     public Text text;
  14.     int score = 0;
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.         SelectZombie(zombies [0], 0);
  19.         text.text = "Score: " + score;
  20.     }
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.  
  25.         if (Input.GetKeyDown ("left"))
  26.             GetZombieLeft ();
  27.  
  28.         if (Input.GetKeyDown ("right"))
  29.             GetZombieRight ();
  30.  
  31.         if (Input.GetKeyDown ("up"))
  32.             PushUp ();
  33.    
  34.     }
  35.  
  36.     void GetZombieLeft() {
  37.         if (selectedZombiePosition == 0) {
  38.             SelectZombie (zombies [3], 3);
  39.         } else {
  40.             SelectZombie (zombies [selectedZombiePosition - 1], selectedZombiePosition - 1);
  41.         }
  42.     }
  43.  
  44.     void GetZombieRight() {
  45.         if (selectedZombiePosition == 3) {
  46.             SelectZombie (zombies [0], 0);
  47.         } else {
  48.             SelectZombie(zombies[selectedZombiePosition + 1], selectedZombiePosition + 1);
  49.         }
  50.     }
  51.  
  52.     void SelectZombie(GameObject newZombie, int newPosition) {
  53.         selectedZombie.transform.localScale = defaultSize;
  54.  
  55.         selectedZombie = newZombie;
  56.  
  57.         selectedZombie.transform.localScale = selectedSize;
  58.  
  59.         selectedZombiePosition = newPosition;
  60.     }
  61.  
  62.     void PushUp() {
  63.         Rigidbody rb = selectedZombie.GetComponent<Rigidbody> ();
  64.         rb.AddForce (0, 0, 10, ForceMode.Impulse);
  65.     }
  66.  
  67.     public void AddScore() {
  68.         score = score + 1;
  69.         text.text = "Score: " + score;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement