mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-30 12:37:08 +01:00
Building Rework
This commit is contained in:
26
Assets/Buildings/Scripts/BuildingPlacement.cs
Normal file
26
Assets/Buildings/Scripts/BuildingPlacement.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BuildingPlacement : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject terrain;
|
||||
[SerializeField] private GameObject prefab;
|
||||
|
||||
Ray ray;
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Build Button Handler
|
||||
if (Input.GetButtonDown("Build"))
|
||||
{ // Wenn man den Button 'B'
|
||||
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hitData;
|
||||
if (terrain.GetComponent<Collider>().Raycast(ray, out hitData, Mathf.Infinity))
|
||||
{
|
||||
Instantiate(prefab, hitData.point, Quaternion.identity);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user