Okay I have a character code and I want a .PNG of a “Full Health Bar” to be draw on the bottom left of the screen while the character is on 100 health. It keeps giving me the Null reference and something about an Instance error. Anyway here’s my character controller code. Any help would be great, i don’t have a clue what’s wrong. Thanks!!!
var Health = 100;
static var dead = false;
private var walkSpeed : float = 0.5;
private var gravity = 5.0; //New variable for code involving gravity
private var moveDirection : Vector3 = Vector3.zero;
private var charController : CharacterController;
private var strength = 0.5; //New variable for code involing objects the player collides with
//function that enables the keyboard cursors to transform the player direction + play associated annimations
function Start(){
charController = GetComponent(CharacterController);
}
function Update ()
{
if (Health <=100)
{
GUI.DrawTexture(Rect(30,530,80,30), Resources.Load("healthbar_full"));
}
if (Health <=1)
{
dead = true;
}
if(charController.isGrounded == true) //using this code, the character animations should only play while the character is grounded
{
if(Input.GetAxis("Vertical") > .1)//input = upward cursor key or W key
{
walkSpeed = 0.6;
}
if(Input.GetAxis("Vertical") < -.1)//input = downward cursor key or S key
{
walkSpeed = 0.5;
}
transform.eulerAngles.y += Input.GetAxis("Horizontal");
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
}
moveDirection.y -= gravity * Time.deltaTime;
charController.Move(moveDirection*walkSpeed);
}
function OnControllerColliderHit(hit : ControllerColliderHit) //moves any game object with a rigidbody+collider component based on the strength variable
{
var body : Rigidbody = hit.collider.attachedRigidbody;
if (body){
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
body.velocity = pushDir*strength*10;
}
}
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == “EvilShot”)
{ Health -= 10;
Destroy(hit.gameObject);
}
if(hit.gameObject.tag == “SlowingSludgePlane”)
{ walkSpeed = 0.1;
}
}
function OnTriggerExit(hit : Collider){
if(hit.gameObject.tag == “SlowingSludgePlane”)
{ walkSpeed = 0.5;
}
}
function LateUpdate()
{ if(dead)
{
transform.position = Vector3(3386.499,211.0097,707.7693);
dead = false;
}
}