Game Development Reference
In-Depth Information
This breaks down as follows:
(1) else if(Input.GetKeyDown(KeyCode.Alpha0)) {
1.
As with the other cheats, this checks to see if the player has pressed the 0
(zero) button. If true,
(2) player.gameObject.GetComponent(GoRagdoll).Invincibility();
2.
Get the GoRagdoll script of the player game object and call the
Invincibility() function that you will create next. Save the Cheats script,
then open the GoRagdoll script. First add the invincible variable as follows:
#pragma strict
private var childRigidBodies : Rigidbody[];
private var childColliders : Collider[];
(1) public var invincible : boolean = false;
1. First, add a public variable of type boolean named invincible and assign
it the value of false . This way when the game starts, the player is not
invincible.
At the end of the script, add the Invincibility() function:
function Invincibility () {
(2) invincible = !invincible;
}
2. This is a simple toggle, where the value of invincible is reassigned to its
opposing boolean value.
Finally, in the GotoRagdoll() function, add a conditional to test for whether or not the player is
invincible before turning him into a ragdoll:
function GotoRagdoll ()
{
(3) if (!invincible) {
if (childRigidBodies != null) {
for (var childRigidBody : Rigidbody in childRigidBodies) {
childRigidBody.isKinematic = false;
}
}
if (childColliders != null) {
for (var childCollider : Collider in childColliders) {
childCollider.enabled = true;
}
}
gameObject.collider.enabled = false;
gameObject.rigidbody.isKinematic = true;
gameObject.GetComponent(Animator).enabled = false;
gameObject.GetComponent(ThirdPersonCharacter).enabled = false;
gameObject.GetComponent(ThirdPersonUserControl).enabled = false;
}
}
 
Search WWH ::




Custom Search