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 knuckles209cp · Dec 18, 2013 at 06:30 AM · guimoney

It is not possible to invoke an expression of type 'int'.

Im calling a variable from another script and added 50 to my CurrentMoney when i destroy the rigidbody , but this comes up ...

Script :

 function Start () {
 
     CurrentHealth = MaxHealth;
 
 
 }
 
 function ApplyDamage (Damage : float) {
 
 
       if(CurrentHealth < 0){
       
          return;
       
       }
 
 
    CurrentHealth -= Damage;
    
    if(CurrentHealth == 0){
    
    
      Destroy( gameObject );
      var MoneyScript: MoneyScript = GetComponent(MoneyScript); 
      MoneyScript.CurrentMoney + 50(); 
 
      
      
    
    
    }
 
 
 }

ive done alot of research for the past half an hour or hour but still cant find any soloution

Comment
Add comment · Show 4
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 KellyThomas · Dec 18, 2013 at 07:30 AM 1
Share

This bit will cause problems sooner or later:

 var $$anonymous$$oneyScript: $$anonymous$$oneyScript = GetComponent($$anonymous$$oneyScript); 
 $$anonymous$$oneyScript.Current$$anonymous$$oney + 50();

You should ensure that you keep your variable and class names distinct:

 var moneyScript: $$anonymous$$oneyScript = GetComponent($$anonymous$$oneyScript); 
 moneyScript.Current$$anonymous$$oney + 50();
avatar image tanoshimi · Dec 18, 2013 at 07:43 AM 1
Share

Will also cause problems because it's trying to access a component of the just destroyed game object...

avatar image iwaldrop · Dec 18, 2013 at 07:46 AM 0
Share

Tanoshimi,

Since 'Destroy' doesn't actually destroy the object until the end of the current frame, it should still work, but it's an interesting thing to note that, since the GameObject will be destroyed, what is the point of incrementing a value on it.

Good catch.

avatar image KellyThomas · Dec 18, 2013 at 07:57 AM 0
Share

If the health is less that zero, this method returns.

If greater than zero it applies damage, then checks if health is exactly zero to see if it should call Destroy().

i.e. the object is only destroyed if a hit places it at exactly zero health.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by iwaldrop · Dec 18, 2013 at 06:32 AM

The line that reads

 MoneyScript.CurrentMoney + 50(); 

Should read

 MoneyScript.CurrentMoney += 50;

See the difference?

Comment
Add comment · Show 5 · 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 knuckles209cp · Dec 18, 2013 at 06:42 AM 0
Share

yea i see it but i dont get it

avatar image iwaldrop · Dec 18, 2013 at 06:45 AM 1
Share

Ok.

The parenthesis indicate to the compiler that we're calling a function. Empty parenthesis mean that this function requires no parameters, where things inside the parenthesis are the parameters that the function needs in order to do it's work. Either way, we still need to let the compiler know what parameters we're supplying when we 'Invoke' (there's that word) the function.

An integer is not a function, it's a value. Values don't do any work. You can't pass parameters to a value. Let me know if you are still confused.

avatar image fafase · Dec 18, 2013 at 08:17 AM 0
Share

No offense meant but if you do not get it, it means you are not where you should be. Your are trying to make a game when you do not know how to use basic program$$anonymous$$g.

avatar image knuckles209cp · Dec 19, 2013 at 04:56 AM 0
Share

Yea i know , its just this one little thing , i know the rest ... nearly kind of :) ... Oh iwaldrop Thank you for the information

avatar image iwaldrop · Dec 19, 2013 at 05:14 AM 0
Share

Well, if it works out for you, please accept the answer. If not, let us know what the problem is. We like to keep the board relatively tidy here.

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

20 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

Related Questions

Script to GUI text 1 Answer

If statement only work once? 1 Answer

An instance of type 'Script' is required to access non static member 'Variable' 1 Answer

Help with GUI Currency 1 Answer

Only allow user to instantiate game object when he has a certain amount of points(money) 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