I’m not 100% sure why this isn’t working but I’ve searched online for this issue. I’ve found a few possible solutions but I wanted to ask here first.
I’ve made an avatar creator in Unity3D and it all works brilliantly in the Editor, except for this annoying error: GetComponent requires that the requested component ‘GameObject’ derives from MonoBehaviour or Component or is an interface. I found out where this is going wrong. My clothing objects appear with an assigned button click that’s triggered using SetActive. Also, I used GetComponentInChildren to locate the object in question because it’s a child of an object (specifically my avatar’s body; the clothing objects are separated meshes).
I think I must have done this GetComponent wrong because in my build none of the objects will show up when I click the buttons, but they worked fine in the editor. Is there something I’ve forgotten?
Here’s an example of a script that has a GetComponent method. Several scripts are similar to this depending on the object needed to show.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Hairstyle1Button : MonoBehaviour {
public GameObject hairstyle1;
// Use this for initialization
void Start () {
hairstyle1 = GetComponentInChildren<GameObject> ();
hairstyle1.SetActive (false);
}
public void ShowObject(){
hairstyle1.SetActive (!hairstyle1.activeInHierarchy);
}
// Update is called once per frame
void Update () {
}
}
Any help would be greatly appreciated. Thank you.