60 lines
2.3 KiB
C#
60 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using AsteroidGame.Entities.Structures.Scripts;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace AsteroidGame.Handlers
|
|
{
|
|
public class BuildingHandler : MonoBehaviour
|
|
{
|
|
[Header("Connections")] [SerializeField]
|
|
private Camera _camera;
|
|
|
|
[Header("Assigned on start")] [SerializeField]
|
|
int buildingSelector = 0;
|
|
|
|
[Header("Prefabs")] [SerializeField] private List<StructureBase> buildings = new List<StructureBase>();
|
|
|
|
private void OnClick(InputValue value)
|
|
{
|
|
var tempVec = new Vector3(Mouse.current.position.ReadValue().x, Mouse.current.position.ReadValue().y, -_camera.transform.position.z);
|
|
// var point = _camera.ScreenToWorldPoint(tempVec);
|
|
// var ray = _camera.ScreenPointToRay(tempVec);
|
|
// print($"Mouse:{Mouse.current.position.ReadValue()} world:{point}");
|
|
// if (!Physics.Raycast(ray, out var hit)) return;
|
|
// var pos = hit.transform.position;
|
|
// print($"{hit.transform.name} was hit! world:{pos}");
|
|
Instantiate(buildings[buildingSelector], _camera.ScreenToWorldPoint(tempVec), Quaternion.identity, transform);
|
|
//var spawnPoint = new Vector3(1, 1, 0);
|
|
//Instantiate(buildings[buildingSelector], spawnPoint, Quaternion.identity, transform);
|
|
|
|
// print($"BuildManagerClick");
|
|
}
|
|
|
|
// public void PlaceStructure(GameObject _tileGO)
|
|
// {
|
|
// Tile _tile = _tileGO.GetComponentInChildren<Tile>();
|
|
//
|
|
//
|
|
// Debug.Log($"Placing tower on Tile: {_tileGO.transform.position}");
|
|
// Debug.Log($"Placing tower on Node: {_node.coordinates}");
|
|
//
|
|
// if (scoreHandler.CurrentBalance - buildings[buildingSelector].Cost < 0)
|
|
// {
|
|
// print("Insufficient Funds!");
|
|
// return;
|
|
// }
|
|
// else
|
|
// {
|
|
// scoreHandler.ModifyWealth(-buildings[buildingSelector].Cost);
|
|
// }
|
|
// }
|
|
|
|
|
|
// public Vector2Int GetVector2(GameObject _o)
|
|
// {
|
|
// return new Vector2Int((Mathf.RoundToInt(_o.transform.position.x) / 10),
|
|
// (Mathf.RoundToInt(_o.transform.position.z / 10)));
|
|
// }
|
|
}
|
|
} |