Graphics Reference
In-Depth Information
RaycastHit hit;
The raycast starts at the position of the waypoint (from tempVEC) with 300 units
added straight up to it, to ensure that the raycast starts well above the ground. The ray
direction is −Vector3.up (straight down), but in this call to Physics.Raycast, there is no dis-
tance set, and the ray should detect everything below it no matter how far away:
if(Physics.Raycast(tempVEC + (Vector3.up * 300),
-Vector3.up, out hit)){
tempVEC.y=hit.point.y+15;
}
myTransform is ready to be set up to its new position and rotation:
// reposition the player at tempVEC (the waypoint position
// with a corrected y value via raycast) and also we set the
// player rotation to the waypoint's rotation so that we are
// facing in the right direction after respawning
myTransform.rotation= tempTR.rotation;
myTransform.position= tempVEC;
After the respawn, the player is made invulnerable (by a call to the MakeInvulnerable()
function). Invoke() is used to schedule a call to MakeVulnerable in 3 s time, limiting the
player invulnerability time:
// we need to be invulnerable for a little while
MakeInvulnerable();
Invoke ("MakeVulnerable",3);
Whenever a respawn happens, the weapon is reset to its default setting of using the
first slot:
// revert to the first weapon
if( weaponControl!=null )
weaponControl.SetWeaponSlot(0);
}
The MakeInvulnerable() and MakeVulnerable() functions just set the isVulnerable
Boolean variable to true or false, respectively. When isInvulnerable is true, the collision
function (OnCollisionEnter() from earlier in this script) will ignore collisions with the
projectiles' layer:
void MakeInvulnerable()
{
isInvulnerable=true;
}
void MakeVulnerable()
{
isInvulnerable=false;
}
Search WWH ::




Custom Search