Hello, I have a problem with my script. When a player enters the trigger, they lose 30 out of a 100 life. That’s fine until the player kills the other one. The dead player gets transferred to the spawn point on the killer’s screen, however, on the dead person’s screen they are still there. My question is why does that happen. I have a network view attached to the player.
Here is the player health script:
#pragma strict
var health : int = 100;
var spawnPoints : GameObject[];
var chance : float;
var myText : TextMesh;
function Start () {
spawnPoints = GameObject.FindGameObjectsWithTag("Spawn");
chance = Random.Range(0, spawnPoints.Length);
myText = transform.FindChild("Health").GetComponent.<TextMesh>();
}
function Update () {
if(health <= 0) {
chance = Random.Range(0, spawnPoints.Length);
transform.position = spawnPoints[chance].transform.position;
health = 100;
}
myText.text = "" + health;
}
function Hit (damage : float) {
health -= damage;
}
And here is the trigger enter script (when the player gets hit by the sword):
#pragma strict
var blood : GameObject;
var damage : float = 30;
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "Player") {
Instantiate(blood, transform.position, transform.rotation);
col.SendMessage("Hit", damage, SendMessageOptions.DontRequireReceiver);
}
}
Any help would be greatly appreciated!