Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheVoxyyn · Oct 29, 2011 at 01:40 AM · errordamagecollidehitpointshealth

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);
     }
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheVoxyyn · Oct 29, 2011 at 12:57 AM 0
Share

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);
 }

}

avatar image TheVoxyyn · Oct 29, 2011 at 12:58 AM 0
Share

Aaaand the commenting system screwed the code up. Well, just try and make it out as best you can.

avatar image syclamoth · Oct 29, 2011 at 01:41 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Help with "Kill" script 2 Answers

Unity Error: Only assignment, call, increment, decrement, and new object expressions can be used as a statement 1 Answer

"Health" value doesn't change? 1 Answer

Wrong with script 1 Answer

change model state due to health 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges