// Update is called once per frame
void Update()
{
if (!isDragging || GameHandler.IsGamePaused())
{
return;
}
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
goTo = new Vector3(mousePosition.x, mousePosition.y, 0);//new Vector3(Mathf.Floor(mousePosition.x) + .5f, Mathf.Floor(mousePosition.y) + .5f, 0);
distance = Vector2.Distance(hoverSprite.transform.position, goTo);
goToNormal = (goTo - hoverSprite.transform.position).normalized;
if (distance < Vector2.Distance(hoverSprite.transform.position, hoverSprite.transform.position + goToNormal * speed * Time.deltaTime))
{
hoverSprite.transform.position = goTo;
}
else
{
hoverSprite.transform.Translate(goToNormal * speed * Time.deltaTime);
}
if (Input.GetMouseButtonDown(0))
{
if (!ButtonAtPosition())
{
if (cost <= PlayerStats.Money)
{
if (!TurrentAtPosition(hoverSprite.transform.position))
{
if (!RouteAtPosition())
{
Instantiate(dragging, hoverSprite.transform.position, transform.rotation, GamePlayWindow.GetTransform());
PlayerStats.changeMoneyAmount(-cost);
SoundManager.PlaySound(SoundManager.Sound.TowerPlace);
SoundManager.PlaySound(SoundManager.Sound.TowerPurchase);
Destroy(hoverSprite);
dragging = null;
isDragging = false;
}
else
{
UnityEngine.Debug.Log("Route There");
SoundManager.PlaySound(SoundManager.Sound.Error);
}
}
else
{
UnityEngine.Debug.Log("Turrent There");
SoundManager.PlaySound(SoundManager.Sound.Error);
}
}
else
{
UnityEngine.Debug.Log("No Gold");
SoundManager.PlaySound(SoundManager.Sound.Error);
}
}
}
}