InvokeRepeating not working (498565)

This Invoke Repeating never starts when it should, this code is done outside of Update:

var rangeAttack : float; 
rangeAttack = Vector3.Distance(transform.position, conanPosition.position);

if (rangeAttack <= 3  dead == false)
{
	InvokeRepeating("Attack1Dmg", 1.0, 1.0);
}

// Attack1 Damage 

	function Attack1Dmg ()
{
	
	var playerScript = GameObject.Find("Player_Conan");
 	playerScript.GetComponent(Player).conanHealth -= 1;
}

Just place prints thru the code. See where it is stopping. See what the relevant values are at that time.

What exactly am I printing? I am a new programmer. And I have a GUI displaying the health, wouldn’t I see if it is starting that way?

print("this will show up in your console at the point in time, this line of code is called");
print("thisValue " + thisValue); /// this line will print a var, thisValue and its value.

I’m lost honestly

print(); is a way to see into your script so to speak.

In your window drop down menu, one window, or tab you can add to your unity project is the console window. Open that up.

Next, select some script running in your project. In the Start function write “print(“hello.”);” run the game and look at your console.

yea I understand what print does, I just don’t understand what to print in order to be helpful in this situation. Thank you for being thorough.

the code checking range attack should be also in a fct or i don’t think is going to work in that form otherwise, then as you will certainly have to check that condition often, i don’t think using invoke is going to be helpfull way to go about it or not the way you use it right now.

Well, perhaps one of your conditions is not being met. So, before you ask “if()” print the values there. The values being what goes into if(). Perhaps the function is not being called at all? Print a print there “function x ()”. Place them strategically, carrying values that let you see into how the script is running.

you need to post more code.

what function is your invoke repeating call sitting inside of?

Hey guys I got this working using it with a trigger instead:

function OnTriggerEnter (other : Collider) 
{
	if (other.gameObject.tag == "Player")
{
	InvokeRepeating("Attack1Dmg", .1, 1.0);
}	

}

function OnTriggerExit (other : Collider) 

{
    CancelInvoke();
}


// Attack1 Damage 

	function Attack1Dmg ()
{
	var playerScript = GameObject.Find("Player_Conan");
 	playerScript.GetComponent(Player).conanHealth -= 1;
}

I am very sure that there are better ways to deal damage however lol. This seems to be working for what I have in the mix right now because the enemy character auto-attacks. So if you play around with the time of the invoke, maybe get the exact time of the animation, it will look pretty decent.