I’ve been trying to make a changeable character scene where on clicking ‘next’ button the character changes I am able to generate the prefab but unfortunately the earlier prefab is never destroyed. What am I doing Wrong, Thanks for the help in advance.
using UnityEngine;
using System.Collections;
public class character_Set : MonoBehaviour {
public GameObject character1;
public GameObject character2;
public GameObject cCharacter;
public int characternum = 1;
private bool startup = true;
// Use this for initialization
void Start() {
cCharacter = Instantiate (character1) as GameObject;
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
if (GUI.Button (new Rect (50, 50, 70, 40), "Next")) {
Destroy(cCharacter);
ChangeCharacters();
}
}
void ChangeCharacters(){
if (characternum == 1) {
cCharacter = Instantiate(character2) as GameObject;
characternum = 2;
}
if (characternum == 2) {
cCharacter = Instantiate(character1) as GameObject;
characternum =1;
}
}
}