using ReadyPlayerMe.Core; using UnityEngine; namespace ReadyPlayerMe.Samples { /// /// This class is a simple to serve as an example on how to load Ready Player Me avatars and spawn as a into the scene. /// public class AvatarLoadingExample : MonoBehaviour { [SerializeField][Tooltip("Set this to the URL or shortcode of the Ready Player Me Avatar you want to load.")] private string avatarUrl = "https://api.readyplayer.me/v1/avatars/638df693d72bffc6fa17943c.glb"; private GameObject avatar; private void Start() { ApplicationData.Log(); var avatarLoader = new AvatarObjectLoader(); // use the OnCompleted event to set the avatar and setup animator avatarLoader.OnCompleted += (_, args) => { avatar = args.Avatar; AvatarAnimatorHelper.SetupAnimator(args.Metadata.BodyType, avatar); }; avatarLoader.LoadAvatar(avatarUrl); } private void OnDestroy() { if (avatar != null) Destroy(avatar); } } }