Hello! I’m developing a 2D mobile game and I have a little problem. I have created a spawn system, that spawns bouncing balls at a random location inside a rectangle. I’m now trying to create a spawn system for another gameobject, this gameobject is meant to show where the bouncing ball will spawn. It’ll only show up for a second just so the player can identify and highlight that “Ahhh an enemy ball will spawn here”. The Gameobject is called “ShowEnemySpawn” and I instantiate it in the same function that spawns out the enemy balls using the same position, I also use InvokeRepeating to make the bouncing balls spawn out every 2 seconds.
How do I spawn the “ShowEnemySpawn” Gameobject for 1 sec before the Bouncing enemy ball spawn?
I’ve been trying to search for a solution, but has been unable to find a one. So I’m really grateful for any help I can get! Here is the code!
using UnityEngine;
using System.Collections;
public class EnemySpawn : MonoBehaviour
{
// EnemyPrefab
public GameObject EnemyBouncingPrefab;
//Show where spawn is prefab
public GameObject ShowEnemySpawn;
// Borders
public Transform borderTop;
public Transform borderBottom;
public Transform borderLeft;
public Transform borderRight;
void Start ()
{
// Spawn boucning enemies every 2 seconds, starting in 3
InvokeRepeating("SpawnBouncingEnemy", 3, 2);
}
// Spawn a Bouncing enemy
void SpawnBouncingEnemy()
{
// x position between left & right border
int x = (int)Random.Range (borderLeft.position.x,
borderRight.position.x);
// y position between top & bottom border
int y = (int)Random.Range (borderBottom.position.y,
borderTop.position.y);
// Sets the prefab where an enemy will spawn
Instantiate (ShowEnemySpawn, new Vector2 (x, y), Quaternion.identity);
// Instantiate the power up at (x, y)
Instantiate (EnemyBouncingPrefab,
new Vector2 (x, y),
Quaternion.identity); // default rotation
}
}