Hey Guys, i’m with a problem here. I just can’t hold the last object of an array(not his index, but the object attached to this index) and destroy it. I find out how to remove it from the array but I don’t managed to remove it from the scene.
If you guys want, here’s the code ( Some variable names are in portuguese );
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Teste : MonoBehaviour {
public List<GameObject> objetos;
public int deslocamento;
public GameObject prefabObjeto;
// Use this for initialization
void Start () {
objetos = new List<GameObject>();
}
void removerArray (int posicao) {
objetos.RemoveAt (posicao);
}
// Update is called once per frame
void Update () {
if(Input.GetButtonUp ("Fire1"))
{
deslocamento += 10;
GameObject newObj;
newObj = (GameObject)Instantiate (prefabObjeto, transform.position, Quaternion.identity);
newObj.transform.position = (new Vector3(0 + deslocamento, 30, 0));
objetos.Add (newObj);
}
else if (Input.GetButtonUp("Fire2") && (objetos.Count > 0))
{
int ultimoObjeto;
ultimoObjeto = objetos.Count - 1;
removerArray(ultimoObjeto);
}
}
}
Variable meaning in English
objetos = objects.
posicao = position.
prefabObjeto = objectPrefab.
deslocamento = displacement.
Hope yous guys may help me out in this.
Thanks from now!
*Sorry for my bad English.