- Home /
The question is answered, right answer was accepted
Expression denotes a `method group', where a `variable', `value' or `type' was expected
Hi, so I started working on the AI attack function, I am having some problems tho, in the last line of this part of my script:
void Attack () {
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit)){
if(hit.distance <= minimumDistance && hit.transform.tag == "Player"){
hit.collider.gameObject.GetComponent<Player>.health -= damage;
in the last line I am getting this error: Assets/Scripts/AI/EnemyMeleeAttack.cs(31,57): error CS0119: Expression denotes a method group', where a
variable', value' or
type' was expected, it's not the first time I have this error, I had it in one line that is above:
GameObject tempClosestEnemy = gameObject.GetComponent<EnemyScript>().closestPlayer;
if(Vector3.Distance(transform.position, tempClosestEnemy.transform.position) <= minimumDistance){
but I fixed it creating the temporary variable to store the value, it worked (btw is the var type supposed to be GameObject?) so in the line that I am having the error I also tried making a temporary variable (GameObject type) to store it, but I was getting this error: Assets/Scripts/AI/EnemyMeleeAttack.cs(31,87): error CS0119: Expression denotes a method group', where a
variable', value' or
type' was expected in the temporary variable line, and this error: Assets/Scripts/AI/EnemyMeleeAttack.cs(32,33): error CS0019: Operator -=' cannot be applied to operands of type
UnityEngine.GameObject' and `int' in the second line:
GameObject tempPlayerHealth = hit.collider.gameObject.GetComponent<Player>.health;
tempPlayerHealth -= damage;
help me please! and thanks in advance
Does a collider
have a gameObject
? It's not listed at http://docs.unity3d.com/Documentation/ScriptReference/Collider.html.
Answer by Graham-Dunnett · Jul 19, 2013 at 11:02 AM
The documentation for GetComponent
shows that it is a function and so need parentheses.
how did I miss that o.O, I already knew that bt totally escaped me-.- thanks anyway!