.Soo… I have a bool method that returns true if the statement is true and returns false if the statement is false.
When I check for the function returning true I don’t get any action… I have searched the internet for quite a bit and I cant find anything that will help me.
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Enemy
{
public class Spawner : MonoBehaviour
{
public GameObject Enemy;
private float spawnRadius = 15f;
private Vector3 spawnPosition = new Vector3(0, 0, 0);
private float timeDelay = 0.1f;
private float nextSpawnTime;
void OnEnable()
{
}
void OnDisable()
{
}
void SetInitialReferences()
{
}
void SpawnEnemy()
{
spawnPosition = transform.position + Random.insideUnitSphere * spawnRadius;
Instantiate(Enemy, spawnPosition, Quaternion.identity);
}
// Use this for initialization
void Start()
{
//SpawnObject();
}
private bool CheckSpawnAllowed()
{
if (Time.time >= nextSpawnTime)
{
nextSpawnTime = Time.time + timeDelay;
return true;
}
else
{
return false;
}
}
// Update is called once per frame
void Update()
{
if (CheckSpawnAllowed())
{
SpawnEnemy();
}
else
{
}
}
}
}
I have checked if the game gets to the return true and it does but if(CheckSpawnAllowed()) must not equal true and so I don’t know what to do. There are no errors that pop up.
Please help ![]()