Home > Net >  Hide 3D object at start of scene until certain condition met
Hide 3D object at start of scene until certain condition met

Time:11-28

Developing a 3D VR application on Unity using OpenXR (2021.3.11f1).

I'm trying to make it so that a Canvas is hidden until a certain condition is met. That condition is that another 3D object's x position is under 45. Here is my script right now:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OptionsBox : MonoBehaviour
{

    public GameObject canvas;
    public GameObject playerObj;

    void Start()
    {
        canvas.SetActive(false);
    }

    void Update()
    {
        if (playerObj.transform.position.x < 45){
            canvas.SetActive(true);
        }
    }
}

I then made an empty GameObject and inputted the script into there:

enter image description here

However, when I run my scene, the canvas is still displayed. What have I done wrong?

CodePudding user response:

No problem with the script. Problem was the other object started at a x value less than 45, so it was always set to True.

CodePudding user response:

You can add a CanvasGroup to the Canvas and play with the opacity property called Alpha

  • Related