Advertisement
truffy14

TutoUnity [5]

Feb 5th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class SlidManager : MonoBehaviour {
  7.  
  8.     public GameObject prefabs;
  9.     public int slidNb;
  10.     public List<GameObject> slids;
  11.  
  12.     void Start () {
  13.         slids = new List<GameObject> ();
  14.         while (slidNb < 5) {
  15.             AddSlid ();
  16.         }
  17.     }
  18.  
  19.     public void AddSlid(){
  20.         if (slidNb < 10) {
  21.             slids.Add (Instantiate (prefabs, transform.position, transform.rotation, transform) as GameObject);
  22.             slids [slidNb].GetComponent <Image> ().color = Random.ColorHSV (0, 1, 0.5f, 1, 1, 1);
  23.             slidNb++;
  24.         }
  25.     }
  26.     public void RemoveSlid(){
  27.         if (slidNb > 0) {
  28.             int lenght = slids.Count;
  29.             slids.Remove (slids [lenght - 1]);
  30.             Destroy (transform.GetChild (lenght - 1).gameObject);
  31.             slidNb--;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement