using UnityEngine; using System.Collections;
public class ChangingRoom : MonoBehaviour { private int _charModeIndex = 0;
private CharacterAsset ca;
private string _charModeTag = "x6";
// Use this for initialization
void Start () {
ca = GameObject.Find("Character Asset Manager").GetComponent<CharacterAsset>();
InstantiateCharacterModel();
}
void OnGUI(){
ChageCharacterMash();
}
private void ChageCharacterMash(){
if(GUI.Button(new Rect(Screen.width / 2 - 60, Screen.height - 35,120,30),_charModeTag)){
_charModeIndex++;
InstantiateCharacterModel();
}
private void InstantiateCharacterModel(){ switch(_charModeIndex){ case 1: _charModeTag = "camaro"; break; default: _charModeIndex = 0; _charModeTag = "x6"; break; } } if(transform.childCount > 0) for(int cnt = 0; cnt < transform.childCount ; cnt++) Destroy(transform.GetChild(cnt)); GameObject model = Instantiate(ca.characterMesh[_charModeIndex],transform.position,Quaternion.identity) as GameObject;
model.transform.parent = transform;
model.transform.rotation = transform.rotation;
}
}
What could be wrong here because I have this error: "Can't destroy Transform component. If you want to destroy the game object please call 'Destroy' on the game object instead. Destroying the transform component is not allowed."
Try reformatting your code. This is not so easy to read. Code should be indented with 4 spaces. Or select your code and press the 0101010 button.
– Marnix