Hi !
So I’m having this weird issue. I’m building this game where I instantiate enemies in running time every given seconds. I have two types of enemies to instantiate, one is working OK, but the second type isn’t displayed event though it is created in my hierarchy. Even weirder, when I press pause in game, they are visible in the game screen. I’ve checked the prefab’s order in layer and it’s OK. Here’s my script, note that both types of enemies use more or less the same script, with only slight changes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InstantiateBomber : MonoBehaviour
{
private float bomberSpawnRate = 2.5f;
public GameObject bomberPrefab;
public Transform spawn_1, spawn_2, spawn_3, spawn_4, spawn_5, spawn_6, spawn_7, spawn_8;
private float timer;
private float waitTime = 5.0f;
private int spawn_point;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("CreateBomber", 0.5f, bomberSpawnRate);
}
void Update()
{
timer += Time.deltaTime;
if (timer > waitTime)
{
if (bomberPrefab.GetComponent<BomberMove>().moveSpeed < 15.0)
{
bomberPrefab.GetComponent<BomberMove>().moveSpeed = AddSpeed(bomberPrefab.GetComponent<BomberMove>().moveSpeed);
}
timer = timer - waitTime;
}
}
void CreateBomber()
{
spawn_point = Random.Range(1, 9);
switch (spawn_point)
{
case 1:
Instantiate(bomberPrefab, spawn_1.position, spawn_1.rotation);
break;
case 2:
Instantiate(bomberPrefab, spawn_2.position, spawn_2.rotation);
break;
case 3:
Instantiate(bomberPrefab, spawn_3.position, spawn_3.rotation);
break;
case 4:
Instantiate(bomberPrefab, spawn_4.position, spawn_4.rotation);
break;
case 5:
Instantiate(bomberPrefab, spawn_5.position, spawn_5.rotation);
break;
case 6:
Instantiate(bomberPrefab, spawn_6.position, spawn_6.rotation);
break;
case 7:
Instantiate(bomberPrefab, spawn_7.position, spawn_7.rotation);
break;
case 8:
Instantiate(bomberPrefab, spawn_8.position, spawn_8.rotation);
break;
}
}
float AddSpeed(float newSpeed)
{
newSpeed += 0.2f;
return newSpeed;
}
}