hay hay, i create code for my caracter costumize, when button j press change clothes, this my code Code (CSharp): using UnityEngine; using System.Collections; public class Costumize : MonoBehaviour { public GameObject[] baju; // aray clothes gameobject int bagian = 0; void Start () { } // Update is called once per frame void test() { baju[bagian].gameObject.SetActive (true); bagian += 1; } void Update () { if (Input.GetKeyDown (KeyCode.J)) { if (bagian == 0 ){ for (int x = 0 ; x < baju.Length ; x++ ){ baju[x].gameObject.SetActive (false); } Invoke ( "test", 1); } else if ( bagian == 1) { for (int x = 0 ; x < baju.Length ; x++ ){ baju[x].gameObject.SetActive (false); } baju[bagian].gameObject.SetActive ( true); bagian =0; } } } } this code work fine but in my console show error i want clean code, any one show me where problem?
What is costumize on? Either the value of Costumize is null or the object is being destroyed. It may be because of your Invoke if you are turning off all objects. But would have to know more about your setup.
Code (CSharp): for (int x = 0 ; x < baju.Length ; x++ ){ baju[x].gameObject.SetActive (false); } this loop for deactive object from my hierarchy, in hierarchy im un check for active for all my clothes object , i mean deactive object use loop then active again use invoke Code (CSharp): void test() { baju[bagian].gameObject.SetActive (true); bagian += 1; } when pust J object next from object[0] to next object "Sory for my bad english"
What are you doing to the gameobject the Customize class is on? It seems like you destroy that somewhere so when Invoke wants to invoke the method after a second the customize class is destroyed.
this problem solved by my self thank for interest this my fix code Code (CSharp): using UnityEngine; using System.Collections; public class Costumize : MonoBehaviour { public GameObject[] baju; int bagian = 0; // baju // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetKeyDown (KeyCode.J)) { if (bagian < baju.Length ) { for (int x = 0 ; x < baju.Length ; x++ ){ baju[x].gameObject.SetActive (false); } baju[bagian].gameObject.SetActive (true); bagian ++; Debug.Log (bagian); } else if ( bagian >= baju.Length) { for (int x = 0 ; x < baju.Length ; x++ ){ baju[x].gameObject.SetActive (false); } baju[baju.Length-1].gameObject.SetActive ( true); bagian =0; Debug.Log (bagian); } } }