using UnityEngine; namespace Unity.Cinemachine.Samples { /// This behaviour works in conjunction with PlayerOnSurface to keep the player /// parented to the surface it's standing on. This is useful to prevent sliding /// when the surface is in motion [RequireComponent(typeof(PlayerOnSurface))] public class ReparentPlayerToSurface : MonoBehaviour { PlayerOnSurface m_PlayerOnSurface; void OnEnable() { if (TryGetComponent(out m_PlayerOnSurface)) m_PlayerOnSurface.SurfaceChanged.AddListener(OnSurfaceChanged); } void OnDisable() { if (m_PlayerOnSurface != null) m_PlayerOnSurface.SurfaceChanged.RemoveListener(OnSurfaceChanged); } // newSurface may be null, in which case we should just uparent the player void OnSurfaceChanged(Collider newSurface) { transform.SetParent(newSurface == null ? null : newSurface.transform, true); } } }