- Home /
Fixing a BCE0051 error
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?
Answer by joedrigon · Nov 02, 2010 at 04:53 PM
I think its upset that you are trying to multiply a gameobject by a floating point number... you can't do that.
var playerIdleQuotient = playerHealth * 0.25;
You need it to be something like var playerIdleQuotient = GameObject.playerHealth * 0.25; where playerHealth is some number attached to the game object...
After doing this, I get a BCE0019 saying that 'playerHealth' is not a member of 'UnityEngine.GameObject'. playerHealth is co$$anonymous$$g from a separate script, so could it be that I'm trying to access it incorrectly?
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.
Your answer
Follow this Question
Related Questions
Complex inequalities? 2 Answers
< cheaper than <= ? 2 Answers
Having random operators in an equation? 1 Answer