Quantcast
Channel: Questions in topic: "findgameobjectswithtag"
Viewing all articles
Browse latest Browse all 230

How to change variables inside FindGameObjectsWithTag objects

$
0
0
so i am instantiating bombs in different location and set their tag to "Bomb" and i want when the player scores more the speed of the bombs will increase so i made a switch statement in which i put the cases of the score and tried to change the speed of the gameobjects that has the tag "Bomb" i couldnt so i stored those bombs in gameobject array and tried again and i couldn't so i made an array of speed and made a for function in which i can assign to each gameobject a speed but unfortunatly i couldnt either and the last error was : IndexOutOfRangeException: Array index is out of range. UIMANAGEMENT.Update () (at Assets/Scripts/UIMANAGEMENT.cs:33) i made an if statement to detect if the bombs exists in the scene then start the for function but again i couldnt so please help me make the bombspeed changes when the player scores higher score and thank you very much here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine; public class UIMANAGEMENT : MonoBehaviour { public Text Paused; public Text Score; public int[] BombSpeed; public bool right; public GameObject[] explosion; public bool left; public float PlayerScore; void Start(){ } public void Pause(){ if (Time.timeScale == 1) { Time.timeScale = 0; Paused.text = "Game Paused !"; } else if (Time.timeScale == 0) { Time.timeScale = 1; Paused.text = ""; } } void Update(){ explosion = GameObject.FindGameObjectsWithTag ("Bomb"); if (GameObject.FindWithTag ("Bomb")) { for (int i = 0; i <= explosion.Length; i++) { BombSpeed [i] = explosion [i].GetComponent ().speed; switch ((int)PlayerScore) { case 0: BombSpeed [i] = 3; break; case 100: BombSpeed [i] = 4; break; case 300: BombSpeed [i] = 6; break; case 1000: BombSpeed [i] = 8; break; case 1500: BombSpeed [i] = 10; break; case 3000: BombSpeed [i] = 12; break; case 5000: BombSpeed [i] = 15; break; default: break; } } } PlayerScore += 13 * Time.deltaTime; Score.text = "Score: " + PlayerScore.ToString("0"); } }

Viewing all articles
Browse latest Browse all 230

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>