Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GridManager : MonoBehaviour {
  5.  
  6.     public GameObject test;
  7.     public RaycastHit2D hit;
  8.     public RaycastHit2D hitForTower;
  9.  
  10.     //So variables arrays for each tile almost
  11.     public GameObject[] row1;
  12.     public GameObject[] row2;
  13.     public GameObject[] row3;
  14.  
  15.     public GameObject[] towers;
  16.     public GameObject towerSelected;
  17.     public Game_Manager gm;
  18.  
  19.  
  20.     public int row1EnemyCount, row2EnemyCount, row3EnemyCount, overallEnemyCount;
  21.  
  22.     //assign the collision detection for them
  23.     void Start()
  24.     {
  25.         row1EnemyCount = 0;
  26.         row2EnemyCount = 0;
  27.         row3EnemyCount = 0;
  28.         overallEnemyCount = 0;
  29.         gm = FindObjectOfType<Game_Manager> ();
  30.  
  31.     }
  32.  
  33.     //depending which one you click saves the active click?
  34.  
  35.     void Update()
  36.     {
  37.         if (Input.GetMouseButtonDown (0)) { //Has the mouse clicked?
  38.             hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (Input.mousePosition), Vector2.zero);
  39.             hitForTower = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (Input.mousePosition), Vector2.zero, 1 << LayerMask.NameToLayer ("Grid"));
  40.             //Find out what the click was
  41.             Debug.Log (hit.collider.gameObject.name);
  42.  
  43.             //So from here its what do you want to do with when you click and stuff.
  44.             //I click tile, if I've select tower 1, then I want to instantiate tower 1 on that tile, so instantiate that tower position = tile position.
  45.             if (hitForTower.collider.gameObject.name == "TowerEasyBuy" && gm.points >= 100) {
  46.                 towerSelected = towers [0];
  47.                 gm.DecreasePoints (100);
  48.             }
  49.             else if (hitForTower.collider.gameObject.name == "TowerMediumBuy" && gm.points >= 200) {
  50.                 towerSelected = towers [1];
  51.                 gm.DecreasePoints (200);
  52.             }
  53.             else if (hitForTower.collider.gameObject.name == "TowerHardBuy" && gm.points >= 300) {
  54.                 towerSelected = towers [2];
  55.                 gm.DecreasePoints (300);
  56.             }
  57.  
  58.             //If I have a selected tile and I have a tower saved
  59.             if (towerSelected && hitForTower.collider.gameObject.tag == "FloorSquare")
  60.             {
  61.                 GameObject newTower = Instantiate (towerSelected);
  62.                 newTower.transform.position = hit.collider.gameObject.transform.position;
  63.                 towerSelected = null;
  64.             }
  65.  
  66.  
  67.         }
  68.         //Calculates overall enemy count
  69.         overallEnemyCount = row1EnemyCount + row2EnemyCount + row3EnemyCount;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement