Exemple #1
0
    private void SpawnCar()
    {
        var policeCar = Instantiate(carPrefab, _spawnCar.position, Quaternion.identity);

        policeCar.GetComponent <Car>().Waypoints       = _waypoints;
        policeCar.GetComponent <Car>().CurrentWaypoint = _waypoints.GetFirstWaypoint();
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (_cars >= _maxCars)
        {
            return;
        }

        _spawnTimer += Time.deltaTime;

        if (_spawnTimer > _spawnTime)
        {
            _spawnTime  = Random.Range(_minSpawnTime, _maxSpawnTime + 1);
            _spawnTimer = 0;
            _cars      += 1;
            var car = Instantiate(carPrefab, transform.position, Quaternion.identity);
            car.transform.localScale = Vector3.one;
            car.transform.SetParent(transform);
            car.GetComponent <Car>().Waypoints       = _waypoints;
            car.GetComponent <Car>().CurrentWaypoint = _waypoints.GetFirstWaypoint();
        }
    }
Exemple #3
0
 // Start is called before the first frame update
 void Start()
 {
     _waypoints       = FindObjectOfType <Waypoints>();
     _currentWaypoint = _waypoints.GetFirstWaypoint();
     _renderer        = GetComponentInChildren <SpriteRenderer>();
 }