- Home /
Player Heal *Help*
All im trying to do is get this script to work.. I want to read when Im in distance of the health fountain my health will go up.
if (animation ["bitchslap"].enabled == true) {
GameObject[] heals = GameObject.FindGameObjectsWithTag ("heal");
foreach (GameObject target in heals) {
float distance = Vector3.Distance (target.transform.position, transform.position);
if (distance < 8) {
PlayerHealth eh = (PlayerHealth)target.GetComponent ("PlayerHealth");
eh.AdjustCurrentHealth (-10);
}
}
}
The negative parameter in the line eh.AdjustCurrentHealth (-10); rather suggests that this script will make your health go down, not up. But, as you've not included any of the relevant code nor told us what the actual problem is, it's hard to say any more.
no need to cast PlayerHealth if you do: target.GetComponent() (just a side note :) )
Otherwise, like tanoshimi mentioned, eh.AdjustCurrentHealth (-10); seems to remove 10 health rather than add 10 health.
I know that, it was just for a test, my script that would use the getcomponet command never works, its a Javascript and im calling from a C## but I tried to use the command from the offical page and every time I get some stupid error saying "AttackandHP" cant be found... so i had to work my way around it.
Sorry but you really need to stop and explain your problem: You've pasted a script that "never works", but you haven't explained why. When you've had errors pointed out to you, you've said "I know that" (but how are we meant to know you know that?). You hadn't even mentioned that one script was Javascript and one was C## [sic] until just know, which is almost certainly the actual problem. Why are you mixing languages? Have you placed the PlayerHealth script in the Standard Assets folder so that it is compiled before the healing script you've shown here? Errors are not "stupid" - they only report stupid things in your code.