- Home /
Spawning fireballs at a certain point,Spawning Fireballs at a certain location
I am making a game that I need to spawn fireballs at a certain point and I have no idea how to do it. Here is the code for the spawn.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FireballSpawn : MonoBehaviour { public float minSpawnDelay = 1f; public float maxSpawnDelay = 3f; public GameObject fireballPrefab;
void Start()
{
Spawn();
}
void Spawn()
{
Vector3 spawnPos = transform.position + new Vector3(Random.Range(6, -6), 5, 5);
Instantiate(fireballPrefab, spawnPos, Quaternion.identity);
Invoke("Spawn", Random.Range(minSpawnDelay, maxSpawnDelay));
}
}
,I am making a game and I need to spawn fireballs at a certain point and have no idea how to do it.Here is the code for the spawn.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FireballSpawn : MonoBehaviour { public float minSpawnDelay = 1f; public float maxSpawnDelay = 3f; public GameObject fireballPrefab;
void Start()
{
Spawn();
}
void Spawn()
{
Vector3 spawnPos = transform.position + new Vector3(Random.Range(6, -6), 5, 5);
Instantiate(fireballPrefab, spawnPos, Quaternion.identity);
Invoke("Spawn", Random.Range(minSpawnDelay, maxSpawnDelay));
}
}
Hi, I don't understand what you want to do. I tried this script and it works fine. It spawns fireballs in a random range of points and every random amount of time. Isn't it what you wanted?
Answer by KjipGamer · May 21, 2018 at 02:58 PM
When you mean at a certain point, do you mean in range of the player, at a random location in the world or at a predetermined location?
What I mean is i have platforms for the player to jump on and there are openings for the fireballs to go through to try and hit the player. I need the fireballs to spawn in that one opening. This is also a 2D project.