Assets/1/scripts/EnemyAttack.cs(12,2): error CS0246: The type or namespace name PlayerHealth' could not be found. Are you missing CompleteProject’ using directive?
that is the error, dont found the script but, here are the script who im refering
Assets/1/scripts/EnemyAttack.cs(12,2): error CS0246: The type or namespace name PlayerHealth' could not be found. Are you missing CompleteProject’ using directive?
that is the error, dont found the script but, here are the script who im refering
Posting code is often more useful than screenshots.
A correct file-name only does not mean the class exists and that it’s used correctly. It’s the content which is more important (unless using ScriptableObjects and MonoBehaviours where it should match the file name)…
The error implies that you’re using a type/namespace that cannot be resolved, i.e. it’s not known in the context.
The error even suggests to use a specific namespace.
So in your code, to be more precise, the file where the error occurs, try to add said namespace to the using directives on top of the script or use the fully qualified name.
I already added it to the beginning but it gives that error always ![]()
here :u

Please use code tags to post code. That makes everything a little easier.
using CompleteProject;
oooh i see… :u thanks
well this the player hp’s script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
namespace CompleteProject
{
public class PlayerHealth : MonoBehaviour
{
public int startingHealth = 100; // The amount of health the player starts the game with.
public int currentHealth; // The current health the player has.
public Slider healthSlider; // Reference to the UI's health bar.
public Image damageImage; // Reference to an image to flash on the screen on being hurt.
public AudioClip deathClip; // The audio clip to play when the player dies.
public float flashSpeed = 5f; // The speed the damageImage will fade at.
public Color flashColour = new Color(1f, 0f, 0f, 0.1f); // The colour the damageImage is set to, to flash.
Animator anim; // Reference to the Animator component.
AudioSource playerAudio; // Reference to the AudioSource component.
playermovement playermovement;// Reference to the player's movement. // Reference to the PlayerShooting script.
bool isDead; // Whether the player is dead.
bool damaged; // True when the player gets damaged.
void Awake ()
{
// Setting up the references.
anim = GetComponent <Animator> ();
playerAudio = GetComponent <AudioSource> ();
playermovement = GetComponent <playermovement> ();
// Set the initial health of the player.
currentHealth = startingHealth;
}
void Update ()
{
// If the player has just been damaged...
if(damaged)
{
// ... set the colour of the damageImage to the flash colour.
damageImage.color = flashColour;
}
// Otherwise...
else
{
// ... transition the colour back to clear.
damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
}
// Reset the damaged flag.
damaged = false;
}
public void TakeDamage (int amount)
{
// Set the damaged flag so the screen will flash.
damaged = true;
// Reduce the current health by the damage amount.
currentHealth -= amount;
// Set the health bar's value to the current health.
healthSlider.value = currentHealth;
// Play the hurt sound effect.
playerAudio.Play ();
// If the player has lost all it's health and the death flag hasn't been set yet...
if(currentHealth <= 0 && !isDead)
{
// ... it should die.
Death ();
}
}
void Death ()
{
// Set the death flag so this function won't be called again.
isDead = true;
// Tell the animator that the player is dead.
anim.SetTrigger ("Die");
// Set the audiosource to play the death clip and play it (this will stop the hurt sound from playing).
playerAudio.clip = deathClip;
playerAudio.Play ();
playermovement.enabled = false;
}
public void RestartLevel ()
{
// Reload the level that is currently loaded.
SceneManager.LoadScene (0);
}
}
}
btw i fixed that error ![]()
but i have a little question if u can help me e,e
i want to make the enemy move freely in the map
but if the player gets close to the enemy, he attack him.
This who i got, but idk what write now .-.
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour
{
Transform Player;
UnityEngine.AI.NavMeshAgent nav;
void Awake ()
{
Player = GameObject.FindGameObjectWithTag ("Player").transform;
nav = GetComponent <UnityEngine.AI.NavMeshAgent> ();
}
void Update ()
{
}
}
[\CODE]
The easiest way would be to check the distance on a regular basis. This can be done every frame or every now and then, depends what’s sufficient for your use case.
Other options are line of sight algorithms and the like, but that’s something to look up if you need something more advanced.
ok thanks ![]()