korimeilyK

How to disable and enable the prefab with normcore

Hi. I'm new to the multiplayer game.
I'd like to disable and enable the prefab in my game while running.
I'm using .SetActive() now.

How do I use normcore?
Thank you in advance for the answer.
Solution
----------------------
If you want to remove the object at index 0 after finishing the loop, you can do so by calling the
RemoveAt()
method on the list. Here's how you can modify the previous example:

using UnityEngine;
using Normal.Realtime;

public class ObjectManager : MonoBehaviour {{
    [SerializeField] private List<GameObject> _objects;

    private void Start() {{
        for (int i = 0; i < _objects.Count; i++) {{
            // Get the RealtimeTransform and RealtimeView components
            RealtimeTransform realtimeTransform = _objects[i].GetComponent<RealtimeTransform>();
            RealtimeView realtimeView = _objects[i].GetComponent<RealtimeView>();

            // Request ownership of each component
            if (realtimeTransform != null) {{
                realtimeTransform.RequestOwnership();
            }}
            if (realtimeView != null) {{
                realtimeView.RequestOwnership();
            }}
        }}

        // Remove the object at index 0 after finishing the loop
        if (_objects.Count > 0) {{
            _objects.RemoveAt(0);
        }}
    }}
}}


In this example,
RemoveAt(0)
is called on
_objects
after the
for
loop. This removes the object at index 0 from the list. The
if (_objects.Count > 0)
check is there to ensure that there is at least one object in the list before trying to remove one.
----------------------
Note: you can ask me a follow up question by @ mentioning me again 💬
----------------------
Was this page helpful?