So I can’t seem to figure this one out at all. I’m not sure if I’m explaining this well enough, if so let me know.
Player 1 shoots player 2 and player 2’s health reaches 0. When that happens player 2’s character is destroyed and replaced by a rag doll dead character with a new camera attached to it. Player 2 does a seamless switch from his first camera to the second camera just fine. However, when anyone kills player 2 everyones camera’s in the game is switched to that players view and I simply can’t figure this one out.
I have a camera attached to the head of the rag doll with a network view watching it. I also have a network view watching the following script:
#pragma strict
function Start () {
if(!networkView.isMine){
if(this.GetComponent(Camera)){
this.GetComponent(Camera).camera.enabled = false;
}
if(this.GetComponent(MouseLookPlus)){
this.GetComponent(MouseLookPlus).enabled = false;
}
}
}
This is what I have only the player to check when to spawn the rag doll when they are dead:
@RPC
function Replace() {
// If we have a dead barrel then replace ourselves with it!
// Destroy ourselves
Counter.SpawnedEnemies -= 1;
Network.Destroy(this.gameObject);
if (deadReplacement) {
var dead : Rigidbody = Network.Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation, 1);
//scoreManager.addScore(20);
// For better effect we assign the same velocity to the exploded barrel
dead.rigidbody.velocity = rigidbody.velocity;
dead.angularVelocity = rigidbody.angularVelocity;
}
}
@RPC
function ApplyDamage (damage : int) {
if (hitPoints <= 0.0)
return;
hitPoints -= damage;
if (hitPoints <= 0.0){
networkView.RPC("Replace", RPCMode.AllBuffered);
}
}
Finally I have this attached to the gun that is sending the damage to the player.
var direction = gameObject.transform.TransformDirection(Vector3(Random.Range(-0.01, 0.01) * triggerTime, Random.Range(-0.01, 0.01) * triggerTime,1));
var hit : RaycastHit;
var position = transform.parent.position;
if (Physics.Raycast(position, direction, hit, range, layerMask.value)) {
if (hit.transform.tag == "Enemy" || hit.transform.tag == "Zombie" || hit.transform.tag == "HumanEnemy") {
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
//hit.transform.root.networkView.RPC("ApplyDamage", RPCMode.AllBuffered, damage);
yield WaitForSeconds(0.01);
var bloodHole = Instantiate (Blood, contact, rotation) as GameObject;
if(Physics.Raycast (position, direction, hit, range, layerMask.value)){
if(hit.rigidbody){
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
}
}
}
Help of any kind on this error that I am having would be greatly appreciated.