- Home /
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 :)
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.
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;
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.
Your answer
Follow this Question
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