Recap: Fireworks
Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 54 of 67.
Challenge
MediumMake the Launcher set off fireworks from the Spark prefab:
- Each press of Space bursts 8 sparks.
- Every spark appears exactly 2 units from the launcher, each in its own random direction, with no rotation.
- Each spark is gone 1 second after it appears.
Press Play and press Space a few times, then Check.
Try it yourself
using UnityEngine;
public class Fireworks : MonoBehaviour
{
public GameObject sparkPrefab;
void Update()
{
// Space: 8 sparks, each 2 units away in a random direction, each gone after 1 second
}
}
All lessons in Unity Scripting Basics
1Your First Script
Hello, UnityPlace the CubeMove Every FrameTurn Every SecondSteer with the KeysRecap: Drive the Cube4Vectors
Adding VectorsDirectionsLocal and World SpaceDiagonal SpeedDistance Between ThingsVector3 Is a StructRecap: Drone Pilot7Project: Catch the Star
The CatcherA Falling Star5Transforms and Hierarchy
Parents and ChildrenScaleLook At ThingsMove Toward a PointRecap: Orbiting Moon6GameObjects and Components
References in the InspectorGet a ComponentMissing ComponentsAdd a ComponentRequireComponentShow and HideRecap: Light Switch9Prefabs and Spawning
Prefabs and InstantiateSpawn on a TimerSpawn in a GridLists of ObjectsDestroyRandom SpawnsRecap: Fireworks