forked from mdotstrange/CustomBehaviorDesignerTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisGameObjectAboveOrBelow.cs
56 lines (46 loc) · 1.61 KB
/
isGameObjectAboveOrBelow.cs
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
47
48
49
50
51
52
53
54
55
56
//by MDS
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityVector3
{
[TaskCategory("Basic/GameObject")]
[TaskDescription("Checks if a game object is above or below another using the threshold value. Returns success if true. Stores bool if is above.")]
public class isGameObjectAboveOrBelow : Action
{
public SharedGameObject self;
public SharedGameObject targetGO;
public SharedFloat threshhold;
public SharedBool isAbove;
public SharedBool isBelow;
public SharedFloat heightDifference;
public override TaskStatus OnUpdate()
{
float yDiff = self.Value.transform.position.y - targetGO.Value.gameObject.transform.position.y;
float AbsDiff = Mathf.Abs(yDiff);
heightDifference.Value = AbsDiff;
if(AbsDiff <= threshhold.Value)
{
isAbove.Value = false;
isBelow.Value = false;
return TaskStatus.Failure;
}
else if(yDiff < 0f)
{
isAbove.Value = true;
isBelow.Value = false;
return TaskStatus.Success;
}
else if(yDiff > 0f)
{
isAbove.Value = false;
isBelow.Value = true;
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
public override void OnReset()
{
threshhold = null;
isAbove = null;
}
}
}