“This is the 16th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Component activation and hiding:

Use the enable attribute in Renderer:

public class Demo4 : MonoBehaviour {

    public MeshRenderer rander; // Drag and drop assignments in the panel

    void Update () 
    {

        if (Input.GetMouseButtonDown(0))    
        { 
            // Mouse click to switch staterander.enabled = ! rander.enabled; }}}Copy the code

Activation and concealment of objects;

gameObject.SetActive(bool b);

Once the object is hidden (gameobject.setactive (false);) Gameobject.setactive (true); Display it again, because once false, this object is no longer in the scene, using the code gameObject.find (); The code on the object does not execute and the component has no effect

Solutions;

Mount the script on another object and manipulate the object you want to hide by passing gameObject.setActive (true); To activate again

To determine whether the object itself or its parent is visible:

gameObject.activeinhierarchy; // Check whether the component is visible, (read-only)

Mouse cursor display and hide:

Cursor. The visible = false;

Cursor.visible = true ;

Response events – Onenable, OnDisable, OnDeStroy (lifecycle functions)

The three response events are monitored in real time as they run in the project

Both Ondisable and OnDestroy are executed once when the project is finished running

The first two are for game objects, and the last is for the script itself

Time class and Time control

Time Describes the Time class member variables

Time Manager Time Manager

Time from the start of the game to now (read only)

Time.deltaTime is measured in seconds, and the Time to complete the last frame refers to the interval between two frames

Time.fixedTime Time when the latest FixedUpdate has started, in seconds, since the start of the game

Time.Scale transmits the scaling of Time. It can be slow or accelerated

Time; .realtimesinceStratup since the beginning of the game

ScaleTime does not affect realtimeSinceStratup. ScaleTime does not affect realtimeSinceStratup

TimeSincelevelLoad is the same as time in the same scenario. The time is recalculated when the current scenario is switched

Update is better for processing logic

FrameCount keeps track of all the frames

RealtimeSinceStartup is the same as time. Time is the same as time. Time is the same as time. Time is the same as time. Time is the same as time. Time is the same as time. Time is the same as Time

The Time class is a very important and commonly used class in Unity. We can use the Time class to obtain information about Time, can be used to calculate the frame rate, can adjust the speed of Time and other functions.