okay i tried to use the health component in my attack script but i get this error
Assets\EnemyAttack.cs(86,13): error CS0103: The name 'health' does not exist in the current context I think it's a quite simple solution is there can you help me?
don't worry since i'm not that familiar with c# i have a lot of notes in the code to help me understand everything
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Traits;
public class EnemyAttack : MonoBehaviour
{
public float timeBetweenAttacks = 2f;
public int attackDamage = 7;
public AudioSource attackSound;
public GameObject player;
CharacterHealth characterHealth ;
bool isPlayerInRange;
float timer;
private Animator anim;
void Awake()
{
player = GameObject.Find("Player");
var health = player.GetComponent<Health>();
anim = GetComponent<Animator>();
}
void Update()
{
timer += Time.deltaTime;
if (timer >= timeBetweenAttacks && isPlayerInRange)
{
Attack();
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.transform.tag == "Player")
{
isPlayerInRange = true;
}
}
private void OnCollisionExit(Collision collision)
{
if (collision.transform.tag == "Player")
{
isPlayerInRange = false;
}
}
void Attack()
{
timer = 0;
if (attackSound != null)
attackSound.Play();
anim.Play("Attack");
// Solange der Spieler noch leben hat
if (health != null)
{
health.Damage(attackDamage);
}
}
}
Assets\EnemyAttack.cs(86,13): error CS0103: The name 'health' does not exist in the current context I think it's a quite simple solution is there can you help me?
don't worry since i'm not that familiar with c# i have a lot of notes in the code to help me understand everything
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Traits;
public class EnemyAttack : MonoBehaviour
{
public float timeBetweenAttacks = 2f;
public int attackDamage = 7;
public AudioSource attackSound;
public GameObject player;
CharacterHealth characterHealth ;
bool isPlayerInRange;
float timer;
private Animator anim;
void Awake()
{
player = GameObject.Find("Player");
var health = player.GetComponent<Health>();
anim = GetComponent<Animator>();
}
void Update()
{
timer += Time.deltaTime;
if (timer >= timeBetweenAttacks && isPlayerInRange)
{
Attack();
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.transform.tag == "Player")
{
isPlayerInRange = true;
}
}
private void OnCollisionExit(Collision collision)
{
if (collision.transform.tag == "Player")
{
isPlayerInRange = false;
}
}
void Attack()
{
timer = 0;
if (attackSound != null)
attackSound.Play();
anim.Play("Attack");
// Solange der Spieler noch leben hat
if (health != null)
{
health.Damage(attackDamage);
}
}
}