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 Datester35 · Jul 01, 2015 at 07:33 PM · errorgetcomponentsyntaxbar

Unexpected token ) when dealing with getcomponent

I am using my progress bar thing, but it gives me an error. If anyone knows why, please help me out!

 #pragma strict
 
 var spawner = GetComponent();
 var barRenderer = spawner.instance; // bar renderer allows to access rendering properties
 var bar = barRenderer.GetComponent(); // allows to change bar value
 
 // bar.ValueF = 1.0f; - will fill the bar to maximum value
 
 var maxHealth:float = 1000;
 var Health:float = 1000;
 function ApplyDammage (TheDammage : int)
 {
  Health -= TheDammage;
  bar.ValueF = Health/maxHealth;
  if(Health <= 0)
  {
   Dead();
  }
 }
 
 function Dead()
 {
  Destroy (gameObject);
 }

Here is a picture of the errors: http://gyazo.com/562db101fabd75c3c57a1cec0394e2d3

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoseKills · Jul 01, 2015 at 07:37 PM

Just look at the API docs when you have problems with a function. Each GameObject can have any number of components, (transform, SpriteRenderer, MeshRenderer, any Monobehaviour you wrote yourself) and you are not specifying which component to "get" in GetComponent()...

Comment
Add comment · Show 3 · 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
avatar image Datester35 · Jul 01, 2015 at 07:47 PM 0
Share

For some reason I can't put < or > in the question. I had written < EnergyBarSpawnerUGUI >

between the first getcomponent and parentheses

avatar image meat5000 ♦ · Jul 01, 2015 at 07:49 PM 0
Share
 GetComponent(Component)


You need to use the code button 101010. If this doesnt work put spaces around the

avatar image NoseKills · Jul 01, 2015 at 08:07 PM 0
Share

Oh yeah those old angle brackets. Also, if you put them in the title of a question, they break the whole page.

Looks like you were trying to use the C# syntax for that method in your JS class

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GameObject.getComponent problem 2 Answers

Problem calling variable across scripts (Closed) 1 Answer

Load gameoverscreen after condition. Error 1 Answer

Error in my script i don't understand. 0 Answers

AddComponent can't find script name MouseOrbit? 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