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 Dasherz · Jul 11, 2012 at 02:07 PM · methodoverload

The best overload for the method "XXXX" is not compatible with the arguement()

Hey guys I have this code and im getting this error and im not sure why any ideas would be great.

The best overload for the method "HealthLoss.ApplyDamage(float)" is not compatible with the arguement()

 var healthGUI : GUITexture;
 private var healthGUIWidth = 0.0;
 var hitPoints :float;
 var maximumHitpoints = 100;
 var damage = 10;
 
 
 function Awake(){
 healthGUIWidth = healthGUI.pixelInset.width;
 }

 function ApplyDamage (damaged : float){
 if(hitPoints < 0.0)
 return;
 //apply damage
 hitPoints -= damaged;
 
 //are we dead?
 if(hitPoints < 0.0)
 Die();
 }

     function Die(){
   //disable all scripts
 var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
 for(var b in coms){
 var p : MonoBehaviour = byte as MonoBehaviour;
 if(p)
 p.enabled = false;
 }
 hitPoints = maximumHitpoints;
 }

    function LateUpdate(){
    //update gui everyframe
    UpdateGUI();

}

    function UpdateGUI(){
    //Update Health gui
    //Health is rendered using an overlay texture which is scaled down based on health
    // Calculate fraction of how much health we have left (0....1)
    var healthFraction = Mathf.Clamp01(hitPoints / maximumHitpoints);

    //Adjust maximum pixel inset based on it
    healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth *          healthFraction;
    }

    function Update(){
    if(Input.GetKey("w"))
    {
    ApplyDamage();
    }
     }



Cheers for any help on the issue :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Jul 11, 2012 at 02:08 PM

ApplyDamage requires a parameter to say how much damage - but you are calling it at the bottom of your script without a value. You need to pass how much damage.

Comment
Add comment · Show 2 · 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 Dasherz · Jul 11, 2012 at 08:51 PM 0
Share

Hey thanks for your answer im quite new to unity and I dont really understand where I need to declare the damage value. I thought I declared it at the top

LINE5: var damage = 10;

avatar image whydoidoit · Jul 12, 2012 at 06:24 AM 0
Share

ApplyDamage(5);

avatar image
0

Answer by Strings · Jul 12, 2012 at 06:23 AM

When you call ApplyDamage() in your second script, you need to pass it an argument of type float. Like so:

 ApplyDamage(0.1)

Which would do the calculations in ApplyDamage() using 0.1 as the parameter. (I.E. subtract 0.1 from your health variable)

As ApplyDamage doesn't have an overload (can you even overload in Jscript? :p No idea.) You can't call it without passing a float to it.

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

6 People are following this question.

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

Related Questions

Csharp error - PLS help :( | error CS1501 1 Answer

No overload for method 'SaveInfo' takes '3' arguments 0 Answers

No overload for method "Destroy" takes 2 arguments? -1 Answers

Why isn't the best overload method not compatible with the arguments list? 1 Answer

Overloaded methods with one minor difference... Any way to refactor? 2 Answers


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