using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CheckScript : MonoBehaviour
{
public bool CanPlace;
public GameObject CyrcleUse;
private void Start()
{
CanPlace = true;
}
public void OnMouseDown()
{
if(CyrcleUse.activeSelf == false)
{
CyrcleUse.SetActive(true);
}
else if (CyrcleUse.activeSelf == true)
{
CyrcleUse.SetActive(false);
}
}
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.tag == "Road")
{
CanPlace = false;
}
if (collider.gameObject.tag == "Towers")
{
CanPlace = false;
}
}
void OnTriggerStay2D(Collider2D collider)
{
if (collider.gameObject.tag == "Road")
{
CanPlace = false;
}
if (collider.gameObject.tag == "Towers")
{
CanPlace = false;
}
}
void OnTriggerExit2D(Collider2D collider)
{
if (collider.gameObject.tag == "Road")
{
CanPlace = true;
}
if (collider.gameObject.tag == "Towers")
{
CanPlace = true;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class BuyTowers : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public GameObject PistolTowerGive;
public GameObject PistolTowerSet;
public bool UseTower;
public Vector2 mousePos;
private GameObject TowerPistol;
public GameObject ShopPanel;
public void OnPointerDown(PointerEventData pointerEventData)
{
TowerPistol = null;
TowerPistol = Instantiate(PistolTowerGive, transform.position, Quaternion.identity);
UseTower = true;
}
public void OnPointerUp(PointerEventData pointerEventData)
{
if (TowerPistol.GetComponent<CheckScript>().CanPlace == false)
{
Destroy(TowerPistol);
}
UseTower = false;
TowerPistol.transform.GetChild(1).GetChild(1).gameObject.SetActive(false);
TowerPistol.transform.GetChild(1).GetChild(2).gameObject.SetActive(false);
ShopPanel.SetActive(false);
}
public void FixedUpdate()
{
if (UseTower == true)
{
if (TowerPistol.GetComponent<CheckScript>().CanPlace == false)
{
TowerPistol.transform.GetChild(1).GetChild(1).gameObject.SetActive(true);
TowerPistol.transform.GetChild(1).GetChild(2).gameObject.SetActive(false);
}
if (TowerPistol.GetComponent<CheckScript>().CanPlace == true)
{
TowerPistol.transform.GetChild(1).GetChild(2).gameObject.SetActive(true);
TowerPistol.transform.GetChild(1).GetChild(1).gameObject.SetActive(false);
}
TowerPistol.transform.position = mousePos;
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
}
}