MasterOX 水
MasterOX 水2mo ago

How to get local player?

How can i get the local player and assign it to a variable?
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @MasterOX 水. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In NormalVR, you can get the local player using the RealtimeAvatarManager component. This component is responsible for instantiating an avatar prefab to represent the local player and keeping track of avatars that were instantiated for other players in the same room. If the RealtimeAvatarManager component is enabled and realtime is connected to a room, an avatar prefab represented by the localAvatarPrefab property will be instantiated to represent the local client. This prefab needs to include a RealtimeAvatar component on the root in order to function correctly. You can assign the local player to a variable using the localAvatar property of the RealtimeAvatarManager. Here is an example of how you can do this:
using UnityEngine;
using Normal.Realtime;

public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;
private RealtimeAvatar _localAvatar;

private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
_localAvatar = _manager.localAvatar;
}
}
using UnityEngine;
using Normal.Realtime;

public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;
private RealtimeAvatar _localAvatar;

private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
_localAvatar = _manager.localAvatar;
}
}
In this example, _localAvatar is a variable that holds the local player. For more information, you can refer to the RealtimeAvatarManager section (https://normcore.io/documentation/realtime/xr/avatars#realtimeavatarmanager) in the Normcore documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below
MasterOX 水
MasterOX 水2mo ago
it doesnt work:( nvm works