I am working on the ocean-themed interactive face filter lesson (Submission: Ocean-themed face filter - Unity Learn) and I want to implement the UI functionality using C# scripts. My goal is to be able to show and hide child objects of the ARFace’s prefab object using a script.
I created the following script that I have assigned to the first button in my UI. I am able to get the reference to myCube, and calling SetActive(false) in the Start() function seems to work, hiding the object from view on startup. However, when I tap the button, buttonTapped() does get called but nothing happens. The activeSelf property of myCube is indeed true, but I cannot see anything.
What am I doing wrong? I also tried getting the MeshRenderer component and toggling the enabled property but that does nothing. Is it because the object is a child of the ARFace’s prefab object? Am I not retaining the reference properly?
GameObject myCube;
public ARFaceManager faceManager; // assigned from hierarchy
void Start()
{
Transform parentTransform = faceManager.facePrefab.transform;
myCube = parentTransform.Find("MyCube").gameObject;
myCube..SetActive(false);
}
public void buttonTapped()
{
myCube.SetActive(true);
}