Game Development Reference
In-Depth Information
public float fuseLength = 0.1f;
private float destructTime = 0.0f;
void Start()
{
destructTime = Time.time + fuseLength;
}
void Update()
{
if(destructTime<Time.time)
Destroy(gameObject);
}
}
Assign an appropriate value such as 1.25 to the Fuse Length field on the Self
Destruct component in the Inspector panel, and then play the scene again. Now, you
will notice that the enemy's death particle system object will clean itself up after the
specified amount of time.
The swarm
At this point, your standard enemies are now complete! Save the Enemy object
as a Prefab and create another Enemy object on each platform. To keep things
clean, create a new empty object called _EnemyContainer in the Hierarchy tab and
place all of the Enemy objects in there. Play the game and see how each one acts
independently of the others using our events and delegates and effects.
 
Search WWH ::




Custom Search