Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ControladorScrollView : MonoBehaviour
- {
- [SerializeField]
- private GameObject entrada;
- [SerializeField]
- private GameObject saida;
- [SerializeField]
- private GameObject ModeloDoItem;
- private int numero = 1;
- private List<string> nomes = new List<string>();
- private int idAtual = 0;
- public void Adiciona()
- {
- string texto = entrada.transform.Find("Text").gameObject.GetComponent<Text>().text;
- if (texto != "")
- {
- if (!nomes.Contains(texto))
- {
- GameObject item = Instantiate(ModeloDoItem) as GameObject;
- item.transform.SetParent(transform, false);
- item.GetComponentInChildren<Text>().text = texto;
- item.GetComponent<ControladorItem>().SetaId(numero);
- item.name = "item " + numero;
- numero++;
- nomes.Add(texto);
- }
- else
- Debug.Log("Já adicionado");
- }
- else
- {
- Debug.Log("Nome vazio");
- }
- }
- public void Remove()
- {
- string nomeDoItem = "item " + idAtual;
- GameObject item = GameObject.Find(nomeDoItem);
- if (item)
- {
- nomes.Remove(item.GetComponentInChildren<Text>().text);
- Destroy(item.gameObject);
- saida.GetComponent<Text>().text = "Nenhum";
- idAtual = 0;
- }
- else
- {
- Debug.Log("Item não encontrado");
- }
- }
- public void Seleciona(string textoDoItem, int id)
- {
- saida.GetComponent<Text>().text = textoDoItem;
- idAtual = id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement