forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawnerSystem.cs
More file actions
34 lines (31 loc) · 1.07 KB
/
Copy pathSpawnerSystem.cs
File metadata and controls
34 lines (31 loc) · 1.07 KB
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 Unity.Burst;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;
namespace Graphical.PrefabInitializer
{
public partial struct SpawnerSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<Spawner>();
state.RequireForUpdate<ExecuteWireframeBlob>();
}
public void OnUpdate(ref SystemState state)
{
if (Camera.main != null && Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (new Plane(Vector3.up, 0f).Raycast(ray, out var enter))
{
var hit = ray.GetPoint(enter);
var prefab = SystemAPI.GetSingleton<Spawner>().Prefab;
var instance = state.EntityManager.Instantiate(prefab);
var transform = SystemAPI.GetComponentRW<LocalTransform>(instance);
transform.ValueRW.Position = hit;
}
}
}
}
}