You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameObjectSpawnter : MonoBehaviour {
[AutoUI]
public bool is_pwan = true;
[AutoUI]
public int max_amount;
public int now_amount;
[AutoUI]
public float spawnterDelayTime;
public GameObject spawn_obj;
public Transform[] spawn_area;
private float timer = 0;
public bool CanSpawnPooPoo()
{
if (spawn_obj == null)
return false;
if (!is_pwan)
return false;
if (now_amount >= max_amount)
return false;
timer -= Time.deltaTime;
if (timer <= 0)
{
timer = spawnterDelayTime;
return true;
}
return false;
}
public Vector3 spawnPosition()
{
Transform spwanTransform = spawn_area[Random.Range(0, spawn_area.Length)];
Vector3 scale = spwanTransform.lossyScale;
Vector3 spwanPos = spawn_birth_pos(scale);
spwanPos += spwanTransform.position;
now_amount++;
return spwanPos;
}
private Vector3 spawn_birth_pos(Vector3 v)
{
return new Vector3(Random.Range(-v.x / 2, v.x / 2), Random.Range(-v.y / 2, v.y / 2), Random.Range(-v.z / 2, v.z / 2));
}
}