Skip to content

Commit 09d6f83

Browse files
committed
add local position option.
1 parent d2b1062 commit 09d6f83

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Assets/JCSUnity/Scripts/Actions/3D/JCS_3DPositionTileAction.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace JCSUnity
1515
{
16-
1716
/// <summary>
1817
/// If object goes a certain range set back to certain
1918
/// position.
@@ -39,6 +38,10 @@ public class JCS_3DPositionTileAction
3938
[SerializeField]
4039
private Vector3 mAbsolutePositionInAxis = Vector3.zero;
4140

41+
[Tooltip("Use the local position instead of global position.")]
42+
[SerializeField]
43+
private bool mUseLocalPosition = false;
44+
4245

4346
[Header("** - Max Settings (JCS_3DDistanceTileAction) **")]
4447

@@ -72,6 +75,7 @@ public class JCS_3DPositionTileAction
7275
// setter / getter
7376
//------------------------------
7477
public bool Active { get { return this.mActive; } set { this.mActive = value; } }
78+
public bool UseLocalPosition { get { return this.mUseLocalPosition; } set { this.mUseLocalPosition = value; } }
7579

7680
//========================================
7781
// Unity's function
@@ -81,18 +85,25 @@ private void Update()
8185
if (!mActive)
8286
return;
8387

84-
Vector3 newPos = this.transform.localPosition;
88+
Vector3 newPos = this.transform.position;
89+
if (mUseLocalPosition)
90+
newPos = this.transform.localPosition;
8591

86-
if (newPos.x < mMinX || newPos.x > mMaxX)
87-
newPos.x = mAbsolutePositionInAxis.x;
92+
{
93+
if (newPos.x < mMinX || newPos.x > mMaxX)
94+
newPos.x = mAbsolutePositionInAxis.x;
8895

89-
if (newPos.y < mMinY || newPos.y > mMaxY)
90-
newPos.y = mAbsolutePositionInAxis.y;
96+
if (newPos.y < mMinY || newPos.y > mMaxY)
97+
newPos.y = mAbsolutePositionInAxis.y;
9198

92-
if (newPos.z < mMinZ || newPos.z > mMaxZ)
93-
newPos.z = mAbsolutePositionInAxis.z;
99+
if (newPos.z < mMinZ || newPos.z > mMaxZ)
100+
newPos.z = mAbsolutePositionInAxis.z;
101+
}
94102

95-
this.transform.localPosition = newPos;
103+
if (mUseLocalPosition)
104+
this.transform.localPosition = newPos;
105+
else
106+
this.transform.position = newPos;
96107
}
97108

98109
//========================================

0 commit comments

Comments
 (0)