U
U
Uncle Bogdan2022-01-03 00:19:02
Unity
Uncle Bogdan, 2022-01-03 00:19:02

How to get a component from an object? (LeoEcs + UniLeo)?

Hello!

I recently started learning Ecs and made this factory:

public class StreetHeroesFactory : IEcsInitSystem
    {
        private readonly List<Hero> _playerHeroes;
        private readonly MovePoint[] _spawnPoints;
        
        public void Init()
        {
            foreach (var hero in _playerHeroes)
            {
                var randomPoint = GetRandomSpawnPoint();

                var heroObject = Object.Instantiate(hero.MoveHeroObject, randomPoint.Transform.position, Quaternion.identity);
            }
        }
        
        public MovePoint GetRandomSpawnPoint() =>
            _spawnPoints[Random.Range(0, _spawnPoints.Length)];
    }


The factory spawns characters at spawn points. But in the MovePoint class there is an array with more points along which the character walks. It is necessary that when a character spawns, he is given his array of points along which he walks. So here's how to do it? If the list should be stored like this:

[Serializable]
    public struct MovingHeroComponent
    {
        public float StayTime;

        [HideInInspector] public Transform[] MovePoints; // вот точки
    }

    public class MoveHeroComponentProvider : MonoProvider<MovingHeroComponent>
    {
        
    }


I would be grateful for any help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question