forked from mdotstrange/CustomBehaviorDesignerTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateRandomTargetVector3.cs
56 lines (39 loc) · 1.46 KB
/
CreateRandomTargetVector3.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
using UnityEngine;
using System.Collections.Generic;
namespace BehaviorDesigner.Runtime.Tasks.Basic.SharedVariables
{
[TaskCategory("Basic/SharedVariable")]
[TaskDescription("Generates a random vector3 on the X and Y axis from an origin.")]
public class CreateRandomTargetVector3 : Action
{
public SharedGameObject originGO;
public SharedFloat randomHigh;
public SharedFloat randomLow;
public SharedVector3 randomTargetPosition;
private SharedFloat rx;
private SharedFloat rz;
private SharedVector3 originPos;
public override TaskStatus OnUpdate()
{
if (originGO.Value == null)
{
return TaskStatus.Failure;
}
originPos = originGO.Value.gameObject.transform.position;
rx = Random.Range(randomLow.Value, randomHigh.Value);
rz = Random.Range(randomLow.Value, randomHigh.Value);
randomTargetPosition.Value = new Vector3(originPos.Value.x + rx.Value, originPos.Value.y, originPos.Value.z + rz.Value);
return TaskStatus.Success;
}
public override void OnReset()
{
originGO = null;
randomHigh = null;
randomLow = null;
randomTargetPosition = null;
rx = null;
rz = null;
originPos = null;
}
}
}