- Home /
              This post has been wikified, any user with enough reputation can edit it. 
            
 
             
               Question by 
               waqasmajeed · Apr 22, 2015 at 05:26 PM · 
                arrayrandomrandom.rangearray of gameobjects  
              
 
              Generate random no and active that GO using array
In my game i want to show multiple images randomly. I just want to generate a random no and based on that active that specific one image (or deactivate other all). I am passing all images to an array.
This is what i have done so far
 using UnityEngine;
 using System.Collections;
 public class imagehandler : MonoBehaviour 
 {
     public GameObject[] images;
     public GameObject currentimage;
     int index;
     
     void Start()
     {
         images = GameObject.FindGameObjectsWithTag("image");
         index = Random.Range (0, images.Length);
         currentimage = images[index];
         Debug.log (currentimage.name);
     }
 }
need help for activation and deactivation part. Thanks
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by JoeStrout · Apr 22, 2015 at 05:42 PM
 for (int i=0; i<images.Length; i++) {
     images[i].SetActive(i == index);
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                