Advertisement
sphinx2001

PlatformController.cs

Feb 2nd, 2021
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlatformController : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.     private bool showMenu = false;
  9.     public GameObject tower;
  10.     public GameObject prefabTower;
  11.  
  12.  
  13.     void Start()
  14.     {
  15.        
  16.     }
  17.  
  18.     // Update is called once per frame
  19.     void Update()
  20.     {
  21.        
  22.     }
  23.  
  24.     void OnMouseDown()
  25.     {
  26.         showMenu = true;
  27.         Debug.Log("Click");
  28.     }
  29.  
  30.     void OnGUI()
  31.     {
  32.         if(showMenu && !tower)
  33.         {
  34.             Vector3 pos = new Vector3(transform.position.x, transform.position.y, transform.position.z);
  35.             Vector3 crd = Camera.main.WorldToScreenPoint(pos);
  36.             crd.y = Screen.height - crd.y;
  37.  
  38.             GUI.Box(new Rect(crd.x - 150, crd.y - 100, 310, 200), $"Управление башней {gameObject.name}");
  39.             if (GUI.Button(new Rect(crd.x - 145, crd.y - 70, 290, 30), "Купить башню"))
  40.             {
  41.                 showMenu = false;
  42.                 //prefabTower = Resources.Load("Prefabs/Tower", typeof(GameObject));
  43.                 //GameObject instance = Instantiate(Resources.Load("Tower", typeof(GameObject))) as GameObject;
  44.                 tower = Instantiate(prefabTower, gameObject.transform.position, Quaternion.identity);
  45.             }
  46.             if (GUI.Button(new Rect(crd.x - 145, crd.y + 70, 290, 20), "Закрыть меню"))
  47.             {
  48.                 showMenu = false;
  49.             }
  50.         }
  51.        
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement