Game Development Reference
In-Depth Information
17. Then, go to
OnCollisionEnter(collision : Collision)
and add the
following highlighted lines of code:
//Checking for the collision if the rocket hit the AI
public function OnCollisionEnter(collision : Collision) : void {
if (collision.transform.tag == "Rocket") {
var rocket : Rocket = collision.gameObject.
GetComponent(Rocket);
var f_damage : float = rocket.getDamage();
aiHP -= f_damage;
b_isGotHit = true;
if (aiHP <= 0) {
aiHP = 0;
var obj_aiPrefab : GameObject = Instantiate(aiRagdoll,
transform.position, transform.rotation);
GameObject.Destroy(transform.parent.gameObject);
}
}
}
18. Save the
AIController
script, and go back to the
Project
view; click on the
AI
Prefab
, and go to the
Inspector
view.
19. We will go to the
Ai Ragdoll
under the
AIController (Script)
and drag
robot_AI_
ragdoll
to this
Ai Ragdoll
parameter, as shown in the following screenshot:
With that we are done with this step. We can click
Play
and see the result—when we kill the
AI, we will see that the ragdoll game object ( the one that we just created) replaces the AI.