<repo_name>Antoineboulou/ECS<file_sep>/Assets/Testing.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
using Unity.Collections;
using Unity.Rendering;


public class Testing : MonoBehaviour
{
    [SerializeField] private Mesh mesh;
    [SerializeField] private Material material;
    private void Start()
    {
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof (LevelUpComponent),
            typeof (Translation),
            typeof (RenderMesh),
            typeof (LocalToWorld),
            typeof (RenderBounds),
            typeof (MoveSpeedComponent)

        );
        NativeArray<Entity> entityArray = new NativeArray<Entity>(500, Allocator.Temp);
        entityManager.CreateEntity(entityArchetype, entityArray);

        for (int i = 0; i < entityArray.Length; i++) 
        {
            Entity entity = entityArray[i];
            entityManager.SetComponentData(entity, new LevelUpComponent { level = Random.Range(10, 20)});

            entityManager.SetComponentData(entity, new MoveSpeedComponent { speed = Random.Range(1f, 2f)});

            entityManager.SetComponentData(entity, new Translation { 
                Value = new Unity.Mathematics.float3(Random.Range(-8,8f),Random.Range(-5,5f),0)});

            entityManager.SetSharedComponentData(entity, new RenderMesh {
                mesh = mesh,
                material = material
            });
        }

        entityArray.Dispose();

    }
}
<file_sep>/Assets/LevelUpSystem.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;

public class LevelUpSystem : ComponentSystem
{
    protected override void OnUpdate() {
        Entities.ForEach((ref LevelUpComponent levelUpComponent) =>
        {
            levelUpComponent.level += 1f * Time.DeltaTime;
            Debug.Log(levelUpComponent.level);

        });
    
    }


}
