- Home /
Expecting ) found =
I know this has been asked before, but not in this exact way. I've searched for a solid half hour now and haven't found anything on this. I'm trying to get a projectile to hit the player, disappear, and deal damage to the player. I'm getting 3 errors and I'm not sure how to fix them. First is "expecting ), found '='." at line 10. Second is "Unexpected token: Player." at line 10. And lastly, "expecting :, found '-='." at line 12. I'm sure it's something simple... Anyways, code:
private var hitPointsDamager : HitPoints;
var damage = 10.0;
hitPointsDamager = HitPoints.hitPoints;
function OnCollisionEnter(collision : Collision)
{
if(collision.collider.tag = "Player")
{
HitPoints.hitPoints -= damage;
Destroy(gameObject);
}
}
I'm a total n00b when it comes to scripting. I'm just getting into Unity, so I have a very very small idea of what I'm doing. The hitPointsDamager variable was just supposed to bring the HitPoints script into the picture so I could access the HitPoints.hitPoints variable. I'm not even sure I did it right lol. But, after taking your advice and messing with it some more, I've solved my problem. Here's the code in case anyone else comes across this problem.
private var hitPointsDamager : HitPoints;
var damage = 10.0;
hitPointsDamager = GetComponent(HitPoints);
function OnCollisionEnter(collision : Collision) { if(collision.collider.tag == "Player") { HitPoints.hitPoints = HitPoints.hitPoints - damage; Destroy(gameObject); }
else
{
Destroy(gameObject);
}
}
Aaaand the commenting system screwed the code up. Well, just try and make it out as best you can.
Nah, you just need to have four spaces before each line. No, the real screw-up here is the moderation queue! I've already brought it up, but qato doesn't seem to care about usability here.
Answer by syclamoth · Oct 29, 2011 at 12:22 AM
First up, the
if(collision.collider.tag = "Player")
bit is almost certainly wrong. It should be an == sign, which tests for equality, instead of a = sign, which assigns the right-hand-side to the left-hand-side!
Also, correct me if I'm wrong someone who actually knows javascript, but I don't think the -= operator works in that language. Just write it out in full.
There are some other issues here- think very carefully about what you are doing with that hitPointsDamager- is it a HitPoints object, or is it a float? In one place you seem to be treating it as one, and somewhere else you are treating it as something else. Is HitPoints.hitPoints a static member? What is the hitPointsDamager actually there for?