- Home /
c# not going to destination on 0 hp
my script it is supposed to spawn an invisible portal on 0 playerhealth that takes me to dz_Default but nothing happens on 0 playerhealth
///
/// PlayerHealth.cs
/// Display the players health in game
///
/// Attach this class to your player character
///
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
private const string DEFAULT_DROP_ZONE_NAME = "dz_Default";
public GameObject destination;
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI() {
GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
if(curHealth <= 0)
{
destination = GameObject.Find( DEFAULT_DROP_ZONE_NAME );
}
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
public void OnTriggerEnter( Collider other ) {
if( other.transform.CompareTag("Player") )
other.transform.position = destination.transform.position;
}
}
Comment
Best Answer
Answer by getyour411 · Sep 30, 2013 at 11:52 PM
The only thing you are doing on playerHealth = 0 is setting the destination variable to some value, since you have the move code within an OnTriggerEnter(). After this
destination = GameObject.Find( DEFAULT_DROP_ZONE_NAME );
add this
transform.position = destination.transform.position;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
c#help reversing a script 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
I get errorsfor my Click to Move Script 0 Answers
Why does this do nothing (Health Script) 2 Answers