public float speed = 3f; // vijand
public gameObject bandit;
private float spawntimer = 10f; // 30 с
private float timer = 0f; // Houdt tijd bij
Код: Выделить всё
void Update()
{
// Berekening richting speler
Vector3 direction = (player.position - transform.position).normalized;
// Vijand beweegt naar speler
transform.position += direction * speed * Time.deltaTime;
// Vijand kijkt naar speler
transform.LookAt(player);
timer += Time.deltaTime;
if (timer >= spawnTimer)
{
// random positie tussen x = 0 en x = 119.1, y = -0.001 en z = 0 en 99.3
Vector3 randomPos = new Vector3(Random.Range(0f, 119.1f), -0.001f, Random.Range(0f, 99.3f));
Instantiate(bandit, randomPos, Quaternion.identity); // object wordt gespawnt zonder rotatie
timer = 0f;
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -bandit-in