Game_CodeMM/Assets/00_scripts/Backup/BuildingPlacer.cs

26 lines
720 B
C#
Raw Normal View History

2025-10-25 21:27:50 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BuildingPlacer : MonoBehaviour
{
public GameObject buildingPrefab;
// Start is called before the first frame update
void Start()
{
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 gridPos = new Vector3(Mathf.RoundToInt(mousePos.x),
Mathf.RoundToInt(mousePos.y),
0);
GameObject buildPrefab = Instantiate(buildingPrefab, gridPos, Quaternion.identity);
buildPrefab.name = $"Building {gridPos}";
}
}
2025-09-27 20:03:16 +08:00
}