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