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