Protfolio-Emanuel-Polsky / Assets / _Project / Code / Player / Camera / ObjectFollowEntity.cs
ObjectFollowEntity.cs
Raw
using Unity.Entities;
using UnityEngine;

namespace GarmentButton.CameraGeneral
{
    public class ObjectFollowEntity : MonoBehaviour
    {
        private Entity _entity;

        void Awake()
        {
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            _entity = entityManager.CreateEntity(typeof(FollowPlayerObjectTag));
            entityManager.SetComponentData(_entity, new FollowPlayerObjectTag()
            {
                Value = transform
            });
        }

        private void OnDestroy()
        {
#if UNITY_EDITOR
            if (World.DefaultGameObjectInjectionWorld == null)
                return;
#endif
            
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            entityManager.DestroyEntity(_entity);
        }

        //

    }
}