- Home /
function isnt working in the class
hi, i tried making a script and it was working initially when all i had the function do was to subtract health, which was working fine and now when i added all these if statements and stuff, nothing runs, not even the debug.log is unless if i delete everything else i wrote. no errors, either
class Properties{
var maxHealth:int = 100;
var health:int = maxHealth;
var dmgCD:float = 0;
var canGetDmg = true;
function Damage(amount:int){
Debug.Log("hi");
if(canGetDmg){
health -= amount;
canGetDmg = false;
}
while(dmgCD < 2){
dmgCD += Time.deltaTime;
yield WaitForEndOfFrame();
}
if(dmgCD >= 2){
canGetDmg = true;
}
}
}
var p:Properties;
function Start(){
p.Damage(10);
}
It all depends on dmgCD. Where is this and what is it doing?
No errors? If I try to compile this with #pragma strict
, I get six.
this is just attached to a gameobject and it's suppose to be a damage function, and i'm just doing as a test to see if it'll work on the start function. i even call this from an OnCollisionEnter and nothing happens.
@rutter what are the errors, because i have #pragma strict too and nothing is showing?
oh you know what? i deleted some variables that i thought wasn't necessary for this forum thing, and i'm seeing that im forgetting some variables
Your answer
![](https://koobas.hobune.stream/wayback/20220613121314im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiate inside class function returns NullReference 1 Answer
Unity C# Start function without extending Mono 2 Answers
class design preference 1 Answer
Creating a class? 2 Answers