- Home /
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?
Answer by Kona · Feb 19, 2012 at 01:28 AM
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();
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
BurgZergArcade tutorial 5 problem 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
Help with script from Unity BurgZergArcade Tutorial 6 2 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers