Oi guys. I'm trying to add a section to the script that does the character animation that'll change the idle when the player's health is below a certain point:
var runAnimationSpeedModifier = .7;
var playerHealth : GameObject;
playerHealth = GameObject.Find("playerHealth");
var playerIdleQuotient = playerHealth * 0.25;
function Start () {
var run = animation["run"];
run.speed *= runAnimationSpeedModifier;
}
function Update () {
if (playerHealth > playerIdleQuotient) {
if (Input.GetAxis("Horizontal") != 0)
animation.CrossFade ("run");
else
animation.CrossFade ("idle");
}
else {
if (Input.GetAxis("Horizontal") != 0)
animation.CrossFade ("run");
else
animation.CrossFade ("idle_injured");
}
}
Upon saving this code, Unity gives me a BCE0051 error: "Assets/Scripts/Character Controls/CharacterAnimation.js(7,39): BCE0051: Operator '*' cannot be used with a left hand side of type 'UnityEngine.GameObject' and a right hand side of type 'float'."
I've never done any programming before, so I don't understand this at all. What's wrong?
Oh yea, for sure... you need need to call it like this scriptname.playerHealth (where scriptname is the name of the script that has playerHealth) and make sure the variable from the other script is set to public.
– joedrigon