#Unity ECS and Pathing
1 messages · Page 1 of 1 (latest)
Here are my files:
Pathfinding
MovementAuthoring ```c#
using UnityEngine;
using Unity.Entities;
using Unity.Collections;
using Pathfinding;
using Unity.Mathematics;
public struct PathPoint : IBufferElementData
{
public int2 position;
}
public struct MovementComponent : IComponentData
{
public float speed;
public bool isMoving;
public int currentPathIndex;
public int2 goal;
public bool hasRecalculatedPath;
public void SetPath(Path path)
{
isMoving = true;
currentPathIndex = 0;
goal = path.endNode.position;
hasRecalculatedPath = false;
}
}
public class MovementAuthoring : MonoBehaviour
{
public float speed;
private class Baker : Baker<MovementAuthoring>
{
public override void Bake(MovementAuthoring authoring)
{
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
AddComponent(entity, new MovementComponent { speed = authoring.speed });
AddBuffer<PathPoint>(entity);
}
}
}
MovementSystem
UnitPathGiver