Melee combat help!

I am using BurgZergArcade tutorial and i am currently on the melee combat tutorial, now i am using this script which is from that tutorial using UnityEngine; using System.Collections; public class PlayerAttack : MonoBehaviour { public GameObject target; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetKeyUp(KeyCode.F)) { Attack(); } } private void Attack() { EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth"); eh.AddjustCurrentHealth(-10); } } and i am getting a error that states "type 'EnemyHealth' does not contain a definition for 'AddjustCurrentHealth' and no extension method 'AddjustCurrentHealth' of type 'EnemyHealth could be found (are you missing a using directive or an assembly refrence?)"

and i have no idea what this means, could someone help me out?

more ▼

asked Feb 19, 2012 at 01:15 AM

avatar image

16 32 29 31

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

It means that unity can't reach the function / method "AddjustCurrentHealth" of the EnemyHealth class.

Either that method does not exist, or you have spelled it wrong or unity can't reach the file.

Hmm, by the way... I'm not sure but could it be because you are typecasting the target as an EnemyHealth class?

I suppose target is defined as a Gameobject since you're trying to reach a component from it. By adding (EnemyHealth) before target means that you are trying to load that gameobject as if it was a EnemyHealth class ( If I'm not mistaken? ) :P So comment that line out and try this:

EnemyHealth eh = target.GetComponent< EnemyHealth >();

more ▼

answered Feb 19, 2012 at 01:28 AM

avatar image

303 26 21 37

Thanks man, found out the problem and got it settled.

Feb 19, 2012 at 09:06 AM honu919
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Feb 19, 2012 at 01:15 AM

Seen: 1405 times

Last Updated: Feb 19, 2012 at 09:06 AM