Here is the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickForMining : MonoBehaviour
{
public GameObject miner;
public GameObject mainCamera;
int amountOfMiners;
public int changableAmountOfMiners;
public bool canSpawn = true;
public void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Vector3 mouseScreenPosition = Input.mousePosition;
This> Ray ray Camera.main.ScreenToPointRay(mouseScreenPosition);
if(Physics.Raycast(ray, out RaycastHit hitInfo))
{
Spawn(hitInfo.point);
}
}
CanItSpawn();
}
public void Spawn(Vector3 spawnPosition)
{
if (canSpawn == true)
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Instantiate(miner, spawnPosition, Quaternion.identity);
}
}
}
public void CanItSpawn()
{
if (amountOfMiners < changableAmountOfMiners)
{
canSpawn = true;
}
if (amountOfMiners > changableAmountOfMiners)
{
canSpawn = false;
}
if (Input.GetKeyDown(KeyCode.Mouse0))
{
amountOfMiners += 1;
if (amountOfMiners > changableAmountOfMiners)
{
Debug.Log(“Max Amount Of Miners”);
}
}
if (canSpawn == true)
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Spawn();
}
}
}
}