// Update is called once per frame void Update() { timer -= Time.deltaTime; if (timer < 1f) { targetStar = Mathf.RoundToInt(UnityEngine.Random.Range(0, stars.Length)); stars[targetStar].SetActive(true); timer = 20f; mainCamera.enabled = false; actionCamera.enabled = true; } if (stars[targetStar] != null) { starAnim = stars[targetStar].GetComponent <Animator>(); starAnim.SetTrigger("explode"); Debug.Log("Star # " + targetStar + " is exploding!!!"); stars[targetStar].SetActive(false); foreach (GameObject star in stars) { if (counter < 20) { cSpawn = star.GetComponent <CubeSpawn>(); int color = Mathf.RoundToInt(UnityEngine.Random.Range(0, 3)); cubeGO = cSpawn.CubeChooser(color); counter += 1; } } } }
// Update is called once per frame void Update() { timer -= Time.deltaTime; if (timer < 1f) { distanceToTarget = DistanceToTarget(shipAgent, targets); projectileChoice = Mathf.RoundToInt(UnityEngine.Random.Range(0, 2f)); switch (projectileChoice) { case 0: { int randomColor = Mathf.RoundToInt(UnityEngine.Random.Range(0, 4f)); if (distanceToTarget < 1.0f && shipAgent.destination == destination1.position) { cSpawn.CubeChooser(randomColor); // CubeSpawn.transform.position = Vector3.MoveTowards(cannon1.position, pTarget5.position, speed * Time.deltaTime); } if (distanceToTarget < 1.0f && shipAgent.destination == destination2.position) { CubeSpawn = Instantiate(cube, cannon1.position, cannon1.rotation) as GameObject; cSpawn.CubeChooser(randomColor); // CubeSpawn.transform.position = Vector3.MoveTowards(cannon1.position, pTarget5.position, speed * Time.deltaTime); } break; } case 1: { if (distanceToTarget < 1.0f && shipAgent.destination == destination1.position) { missileSpawn = Instantiate(missile1, cannon2.position, cannon2.rotation) as GameObject; } if (distanceToTarget < 1.0f && shipAgent.destination == destination2.position) { missileSpawn = Instantiate(missile1, cannon2.position, cannon2.rotation) as GameObject; } break; } case 2: { if (distanceToTarget < 1.0f && shipAgent.destination == destination1.position) { bombSpawn = Instantiate(bomb, cannon2.position, cannon2.rotation) as GameObject; } if (distanceToTarget < 1.0f && shipAgent.destination == destination2.position) { bombSpawn = Instantiate(bomb, cannon2.position, cannon2.rotation) as GameObject; } break; } } } }