forked from whztt07/UnityGameplayAbilitySystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.cs
More file actions
46 lines (37 loc) · 1.26 KB
/
Copy pathProjectile.cs
File metadata and controls
46 lines (37 loc) · 1.26 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
37
38
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UniRx.Async;
using UnityEngine;
public class Projectile : MonoBehaviour {
// Start is called before the first frame update
public float SeekingSpeed = 1f;
private bool hasCollided = false;
private GameObject TargetCollider = null;
public AnimationCurve Speed;
void Start() {
}
// Update is called once per frame
void Update() {
}
public async Task SeekTarget(GameObject Target, GameObject TargetCollider) {
this.TargetCollider = TargetCollider;
var t = 0f;
while (!hasCollided) {
this.transform.LookAt(Target.transform);
this.transform.position += transform.forward * Time.deltaTime * SeekingSpeed * Speed.Evaluate(t);
// Move closer to target
await UniTask.DelayFrame(0);
t += Time.deltaTime;
}
}
/// <summary>
/// OnTriggerEnter is called when the Collider other enters the trigger.
/// </summary>
/// <param name="other">The other Collider involved in this collision.</param>
void OnTriggerEnter(Collider other) {
if (other.gameObject == this.TargetCollider) {
hasCollided = true;
}
}
}