47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using System;
|
|||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class FurnitureBuilder : MonoBehaviour
|
||
|
|
{
|
||
|
|
[Header("Настройки")]
|
||
|
|
public GameObject currentPrefab;
|
||
|
|
public LayerMask floorLayer;
|
||
|
|
[SerializeField] private GameObject shopPanel;
|
||
|
|
|
||
|
|
private void Start()
|
||
|
|
{
|
||
|
|
currentPrefab = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
if (Input.GetMouseButtonDown(0)&&!shopPanel.activeSelf)
|
||
|
|
{
|
||
|
|
if (currentPrefab != null)
|
||
|
|
{
|
||
|
|
TryPlaceFurniture();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void TryPlaceFurniture()
|
||
|
|
{
|
||
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||
|
|
RaycastHit hit;
|
||
|
|
|
||
|
|
if (Physics.Raycast(ray, out hit, 100f, floorLayer))
|
||
|
|
{
|
||
|
|
Instantiate(currentPrefab, hit.point, Quaternion.identity);
|
||
|
|
currentPrefab = null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public void SelectFurnitureAndCloseShop(GameObject prefabToSelect)
|
||
|
|
{
|
||
|
|
currentPrefab = prefabToSelect;
|
||
|
|
shopPanel.SetActive(false);
|
||
|
|
}
|
||
|
|
public void SelectFurniture(GameObject prefabToSelect)
|
||
|
|
{
|
||
|
|
currentPrefab = prefabToSelect;
|
||
|
|
}
|
||
|
|
}
|