Базовый скрипт для создания предметов
This commit is contained in:
1 parent
4adfb81d1d
commit
b25c561a97
367 files changed
+79704
-28
No files matched your search
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user