47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
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>();
|
|
|
|
#region Private
|
|
|
|
[SerializeField] private List<StructureBase> activeBuildings;
|
|
private Vector3 _tempVec;
|
|
private Plane _buildPlane;
|
|
private StructureBase _tempSB;
|
|
|
|
#endregion
|
|
|
|
private void OnEnable()
|
|
{
|
|
activeBuildings.Clear();
|
|
}
|
|
|
|
private void OnClick(InputValue value)
|
|
{
|
|
_buildPlane = new Plane(Vector3.up, Vector3.zero);
|
|
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
|
|
if (_buildPlane.Raycast(ray, out float distance))
|
|
{
|
|
_tempVec = ray.GetPoint(distance);
|
|
}
|
|
|
|
_tempSB = Instantiate(buildings[buildingSelector], _tempVec, Quaternion.identity, transform);
|
|
|
|
activeBuildings.Add(_tempSB);
|
|
}
|
|
}
|
|
} |