Game Development Reference
In-Depth Information
To have the script work, we need to perform some operations.
1. First of all we need to tag the Aliens prefab as enemies. Add a tag named
Enemies to the Tag Manager panel as we did for levelBound and set it for
the four Alien prefabs.
2. Then we need to program the alien instances so that they alert the
SwarmManager game object whenever they collide with levelBound . As
you may remember, we created the SwarmManager game object as an ex-
ternal component of the swarm itself; therefore we now need to add another
script to our Script folder.
3. Create a new JavaScript file, name it BoundCollision and open it in
MonoDevelop . Add the following lines to the script; a variable declaration
and the OnTriggerEnter() function to actually check the collisions
between the Aliens and the Bounds :
//this variable is used to access the
bCollide variable in
//the ControlSwarm script
var mySwarm:GameObject;
function Start () {
}
function Update () {
}
function OnTriggerEnter(other:Collider)
{
if(other.gameObject.tag=="levelBound")
{
//we access the bCollide
variable in the
//ControlSwarm script
var scriptFile: ControlSwarm =
mySwarm.GetComponent("ControlSwarm");
scriptFile.bCollide=true;
Search WWH ::




Custom Search