- Home /
Operator Cannot Be used with a left hand type 'System.type' and a right hand type 'int'
My script Keeps getting that 2 errors, when I use Health -= Damage, and when explaining the Variable Health,
#pragma strict
var Heath : int = 100;
var bullet : GameObject;
var damage : int;
function Update ()
{
if (Health < 0)
(
DIE());
}
function OnTriggerEnter ( hit : Collider )
{
if(hit.gameObject.tag == "Bullet")
{
bullet = hit.gameObject;
TakeDamage ();
}
}
function TakeDamage ()
{
var BulletScript : Bullet = bullet.GetComponent("Bullet");
damage = BulletScript.Damage;
Health -= damage;
}
function DIE()
{
Debug.Log("I'm Dead!");
Destroy(gameObject);
}
You've misspelled 'Health' in line 3. I'm not sure if this is your problem since you should get an 'unidentified' error not the one you list in the title.
Answer by whydoidoit · May 09, 2013 at 08:19 PM
So this is a perfect example of why following a "variable names are lower case initial letter" and "scripts are upper case first letter" really helps. You have a script called Health, you have a variable you thought was called "Health" but as @robertbu pointed out was called "Heath". If you follow the rule then you would have received a much more meaningful error message about "heath" not being found rather than the compiler thinking you were trying to do something with your Health script.
Answer by Negagames · May 09, 2013 at 08:30 PM
On top of the fact that Health is spelled wrong, you did this in update:
function Update ()
{
if (Health < 0)
(
DIE());
}
as far as my scripting knowledge goes, i'm pretty sure you cant use '(' and ')' to substitute for '{' and '}'.
function Update (){
if (Health < 0){
DIE();
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unity error "scripts exist in multiple locations" 1 Answer
Networking Problem Please Help!!! [IMPORTANT] 0 Answers
my script says OnCollisionEnter() error bce005 and it wont work 3 Answers
Spawn Script Issue 0 Answers