- Home /
I'm Learning to script with a Tutorial video, and can't seem to find the solution to my problem.
I keep getting this error- Assets/Fighter.cs(29,63): error CS1061: Type Mob[]' does not contain a definition for
getHit' and no extension method getHit' of type
Mob[]' could be found (are you missing a using directive or an assembly reference?)
using UnityEngine;
using System.Collections;
public class Mob : MonoBehaviour { public float speed; public float range; public CharacterController controller; public AnimationClip run; public AnimationClip idle;
public Transform player;
private int Health;
// Use this for initialization void Start () { Health = 100; } // Update is called once per frame void Update () { if (!inRange ()) { Chase (); } else { animation.CrossFade(idle.name);
} }
bool inRange () { if(Vector3.Distance(transform.position, player.position)< range) {
return true; } else {
return false;
} }
public void getHit(int damage)
{ Health = Health - damage;
} void Chase() {
transform.LookAt (player.position);
controller.SimpleMove (transform.forward * speed);
animation.CrossFade (run.name);
} void OnMouseOver()
{ player.GetComponent<Fighter> ().opponent = gameobject; } }
The problem is in your Fighter.cs script. You are trying to execute a method using the array rather than an individual entry in the array. Post your fighter script for more info.
}using UnityEngine; using System.Collections;
public class $$anonymous$$ob : $$anonymous$$onoBehaviour { public float speed; public float range; public CharacterController controller; public AnimationClip run; public AnimationClip idle;
public Transform player;
private int Health;
// Use this for initialization
void Start ()
{
Health = 100;
}
// Update is called once per frame
void Update ()
{
if (!inRange ())
{
Chase ();
}
else
{
animation.CrossFade(idle.name);
}
}
bool inRange ()
{
if(Vector3.Distance(transform.position, player.position)< range)
{
return true;
}
else
{
return false;
}
}
public void getHit(int damage)
{
Health = Health - damage;
}
void Chase()
{
transform.LookAt (player.position);
controller.Simple$$anonymous$$ove (transform.forward * speed);
animation.CrossFade (run.name);
}
void On$$anonymous$$ouseOver()
{
player.GetComponent<Fighter> ().opponent = gameObject;
}
}
@Sensui - not sure why you posted the updated version of your $$anonymous$$ob class. The error is on line 29 of your Fighter class. It is likely you have an array of '$$anonymous$$ob' objects and you are trying to use the whole array to get access to the 'getHit' method.