Hi everybody i am making a top down space shooter.
Atm i am trying to instantiate a comet object - it should spawn every three second and spawn at a point between the minDist and the maxDist. For some reason it is not doing that. Anyone got any solutions or suggestions?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomSpawn : MonoBehaviour
{
public float minDist = 10f;
public float maxDist = 20f;
public GameObject objectToSpawn;
public Transform Player;
float Timer;
void Start ()
{
Timer = Time.time + 3;
}
void Update()
{
float distance = Vector3.Distance(transform.position, Player.position);
if (distance >= minDist && distance <= maxDist && Timer < Time.time)
{
Debug.Log("Hello");
Instantiate(objectToSpawn, transform.position, transform.rotation);
Timer = Time.time + 3;
}
}
}