Unity: Make object appear or disappear randomly during game play

后端 未结 1 1279
半阙折子戏
半阙折子戏 2021-01-27 22:45

I\'m creating a 3D, 1st person maze game in Unity. The objective of the game is to reach the other side of the maze before time is up. To make the game fun, for every round a pl

相关标签:
1条回答
  • 2021-01-27 23:43

    There are many ways to make an Object disappear in Unity.

    The wall to make disappear:

    public GameObject wallObject;
    

    1.Deactive it

    wallObject.SetActive(false);
    

    2.Disable the Renderer component of the Wall then the collider so that other GameObjects can pass through it

    wallObject.GetComponent<Renderer>().enabled = false;
    wallObject.GetComponent<Collider>().enabled = false;
    

    3.Destroy it.

    Destroy(wallObject);
    

    You can use Random.Range to generate the number number then use one of the method above to hide that wall.

    0 讨论(0)
提交回复
热议问题