mirror of
https://github.com/Steffo99/gravity-fusion.git
synced 2024-11-28 19:14:30 +00:00
23 lines
633 B
C#
23 lines
633 B
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class SpawnOnMouseClick : MonoBehaviour
|
|||
|
{
|
|||
|
[Header("Config")]
|
|||
|
public GameObject prefabToSpawn;
|
|||
|
public int mouseButton;
|
|||
|
|
|||
|
protected Vector3 GetWorldMousePosition() {
|
|||
|
return Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
if(Input.GetMouseButtonDown(mouseButton)) {
|
|||
|
Vector3 mousePosition = GetWorldMousePosition();
|
|||
|
GameObject instance = Instantiate(prefabToSpawn, new Vector3(mousePosition.x, mousePosition.y, 0f), Quaternion.identity);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|