i have a health bar script, and i made a static variable in it. i made it so a monster follows the main character. The monster's code also has a static variable. In the main character's code, i want to make it so when the monster hits it, it does the health bar's static variable minus the monster's static variable. the health bar's script is called bar, and the monster's script is called beholder. here's the code for the character:
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var turnSpeed : float = 3.0;
var gravity : float = 20.0;
bar.barDisplay = 100;
beholder.damage = 5;
private var moveDirection = Vector3.zero;
private var turnDirection : float = 0;
private var grounded : boolean = false;
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == "Beholder")
{
Debug.Log("hit for " + beholder.damage + "points");
bar.barDisplay -= beholder.damage;
}
}
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
turnDirection = Input.GetAxis("Horizontal");
transform.Rotate(0, turnDirection * turnSpeed ,0);
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
everything else works, but unity says that the identifiers beholder and bar are unknown...