// Update is called once per frame void Update() { if (dead) { this.transform.position = Vector3.Lerp(this.transform.position, new Vector3(this.transform.position.x, -2.5f, this.transform.position.z), speedDeath * Time.deltaTime); if (this.transform.position.y < 2f) { Destroy(this.gameObject); } } else { if (Vector3.SqrMagnitude(this.transform.position - new Vector3(targetPoint.position.x, 0, targetPoint.position.y)) < 1f) { currentPoint = targetPoint; this.transform.position = new Vector3(currentPoint.position.x, 0, currentPoint.position.y); targetPoint = currentPoint.voisins[Random.Range(0, currentPoint.voisins.Count - 1)]; this.transform.LookAt(new Vector3(targetPoint.position.x, 0, targetPoint.position.y)); this.transform.Rotate(90 * Vector3.up); } this.transform.position += speed * Time.deltaTime * (new Vector3(targetPoint.position.x, 0, targetPoint.position.y) - this.transform.position).normalized; UpdateLoop(); } }
public void PopTank(bool notTooMuchClose) { GameObject tank = GameObject.Instantiate(prefabTank, ennemiParent); bool positionOk = false; Map.Voronoi voronoi = null; while (!positionOk) { voronoi = Map.instance.quartiers[Random.Range(0, Map.instance.quartiers.Count - 1)]; if (voronoi.voisins.Count == 0 || (notTooMuchClose && Vector3.SqrMagnitude(new Vector3(voronoi.position.x, 0, voronoi.position.y) - essaimMaitre.transform.position) < raidusMinimumaroundEssaim * raidusMinimumaroundEssaim)) { positionOk = false; } else { positionOk = true; tank.transform.position = new Vector3(voronoi.position.x, 0, voronoi.position.y); } } Vehicule vehicule = tank.GetComponent <Vehicule>(); vehicule.currentPoint = voronoi; vehicule.targetPoint = voronoi.voisins[Random.Range(0, voronoi.voisins.Count - 1)]; Debug.LogWarning((vehicule.currentPoint == null) + " " + (vehicule.targetPoint == null)); listEnnemis.Add(vehicule); nbTank++; }