Need some help creating a new enemy

Hi everyone , i have some troubles trying to create an enemy wich can be visible and invisible every 2 secs and untarggetable while invisible. I tried differents ways to do it but it dosnt work. Here is my Normal enemy script:

public class Enemy : MonoBehaviour {
[HideInInspector]
public float speed;

public float startSpeed = 10f;

public float startHealth = 100;
private float health;

public int cash = 50;

public GameObject deathEffect;

[Header(“Unity Stuff”)]
public Image healthBar;

void Start()
{
speed = startSpeed;
health = startHealth;
}
public void TakeDamage(float amount)
{
health -= amount;
healthBar.fillAmount = health / startHealth;
if (health<=0)
{
Die();
}
}

public void IncreaseHealth(float amount)
{
startHealth += amount;
}

public void Slow(float pct)
{
speed = startSpeed * (1f - pct);
}

public void Die()
{
PlayerStats.Money += cash;
GameObject effect = (GameObject)Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(effect, 3f);

WaveSpawner.EnemiesAlive–;
Destroy(gameObject);
}

public void Ended()
{
Destroy(gameObject);
}
}

I have another script to move my enemy:

[RequireComponent(typeof(Enemy))]
public class EnemyMovement : MonoBehaviour
{

private Transform target;
private int wavepointIndex = 0;

private Enemy enemy;

void Start()
{
enemy = GetComponent();
target = Waypoints.points[0];
}

void Update()
{

Vector3 direccion = target.position - transform.position;
transform.Translate(direccion.normalized * enemy.speed * Time.deltaTime, Space.World);

if (Vector3.Distance(transform.position, target.position) <= 0.4f)
{
GetNextWayPoint();
}

enemy.speed = enemy.startSpeed;
}
void GetNextWayPoint()
{

if (wavepointIndex >= Waypoints.points.Length - 1)
{
EndPath();
return;
}
wavepointIndex++;
target = Waypoints.points[wavepointIndex];
}

void EndPath()
{
PlayerStats.Lives–;
WaveSpawner.EnemiesAlive–;
Destroy(gameObject);
}

please help! thanks

Please use code tags next time…

For something that changes every couple of seconds you could either use the update function or create a co-routine.
A rough something to get you started…

int visibilityTimer = 0; //Tracks how long since the last visibility change
int visibilityInterval = 60; //How long (in frames) it takes to change visibility. 60 assumes we are running at 30fps.

void Update(){
    if (visibilityTimer == visibilityInterval) {
        //Disable a renderer or do whatever you have to do
        //to make your enemy invisbile / visible.

        visibilityTimer = 0;
    } else {
        visibilityTimer++;
    }
}

Thanks so much!!! it works perfectly as i wanted :smile: rlly thx u …
And sorry for no comments im working for being a good professonal!