forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJumpingSpherePSSystem.cs
More file actions
36 lines (31 loc) · 1.01 KB
/
Copy pathJumpingSpherePSSystem.cs
File metadata and controls
36 lines (31 loc) · 1.01 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
35
36
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
[RequireMatchingQueriesForUpdate]
public partial struct JumpingSpherePSSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
}
public void OnDestroy(ref SystemState state)
{
}
public void OnUpdate(ref SystemState state)
{
var time = (float)SystemAPI.Time.ElapsedTime;
var y = math.abs(math.cos(time*3f));
//Make the sphere jumps
foreach (var translation in SystemAPI.Query<RefRW<Translation>>().WithAll<JumpingSphereTag>())
{
translation.ValueRW.Value = new float3(0, y, 0);
}
//Play ParticleSystem when the sphere is touching the ground
foreach (var particleSystem in SystemAPI.Query<SystemAPI.ManagedAPI.UnityEngineComponent<UnityEngine.VFX.VisualEffect>>().WithAll<JumpingSpherePSTag>())
{
if(y < 0.05f) particleSystem.Value.Play();
}
}
}