Спустя неделю мучений, я сделал это и совершенно случайно. Может кому пригодится
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 void Start()
{
}
public void OnPointerDown(PointerEventData pointerEventData)
{
TowerPistol = Instantiate(PistolTowerGive, transform.position, Quaternion.identity);
UseTower = true;
}
public void OnPointerUp(PointerEventData pointerEventData)
{
UseTower = false;
}
public void FixedUpdate()
{
if (UseTower == true)
{
TowerPistol.transform.position = mousePos;
}
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
}