forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityTracker.cs
More file actions
34 lines (31 loc) · 963 Bytes
/
Copy pathEntityTracker.cs
File metadata and controls
34 lines (31 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;
public class EntityTracker : MonoBehaviour, IReceiveEntity
{
private Entity EntityToTrack = Entity.Null;
public void SetReceivedEntity(Entity entity)
{
EntityToTrack = entity;
}
// Update is called once per frame
void LateUpdate()
{
if (EntityToTrack != Entity.Null)
{
try
{
var entityManager = BasePhysicsDemo.DefaultWorld.EntityManager;
transform.position = entityManager.GetComponentData<Translation>(EntityToTrack).Value;
transform.rotation = entityManager.GetComponentData<Rotation>(EntityToTrack).Value;
}
catch
{
// Dirty way to check for an Entity that no longer exists.
EntityToTrack = Entity.Null;
}
}
}
}