Populate minigame with obstacles and monster spawns (#5)
- Simulated "fake" physics and collisions - Object pooling for tiles, obstacles and monster spawns - Base monster scoring with proximity triggers and depth multiplier Co-authored-by: AlexanderT <alexander@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #5
This commit is contained in:
@@ -150,7 +150,7 @@ TextureImporter:
|
|||||||
x: 24
|
x: 24
|
||||||
y: 13
|
y: 13
|
||||||
width: 569
|
width: 569
|
||||||
height: 380
|
height: 384
|
||||||
alignment: 9
|
alignment: 9
|
||||||
pivot: {x: 0.5, y: 0.2}
|
pivot: {x: 0.5, y: 0.2}
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
@@ -169,12 +169,12 @@ TextureImporter:
|
|||||||
name: LawnMowerMovingPLACEHOLDER_1
|
name: LawnMowerMovingPLACEHOLDER_1
|
||||||
rect:
|
rect:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 415
|
x: 416
|
||||||
y: 7
|
y: 7
|
||||||
width: 16
|
width: 14
|
||||||
height: 20
|
height: 20
|
||||||
alignment: 0
|
alignment: 9
|
||||||
pivot: {x: 0.5, y: 0.5}
|
pivot: {x: 0.5, y: 0.2}
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
customData:
|
customData:
|
||||||
outline: []
|
outline: []
|
||||||
@@ -193,8 +193,8 @@ TextureImporter:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 632
|
x: 632
|
||||||
y: 13
|
y: 13
|
||||||
width: 569
|
width: 570
|
||||||
height: 380
|
height: 384
|
||||||
alignment: 9
|
alignment: 9
|
||||||
pivot: {x: 0.5, y: 0.2}
|
pivot: {x: 0.5, y: 0.2}
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
@@ -214,11 +214,11 @@ TextureImporter:
|
|||||||
rect:
|
rect:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 1013
|
x: 1013
|
||||||
y: 12
|
y: 11
|
||||||
width: 24
|
width: 24
|
||||||
height: 24
|
height: 26
|
||||||
alignment: 0
|
alignment: 9
|
||||||
pivot: {x: 0.5, y: 0.5}
|
pivot: {x: 0.5, y: 0.2}
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
customData:
|
customData:
|
||||||
outline: []
|
outline: []
|
||||||
@@ -235,10 +235,10 @@ TextureImporter:
|
|||||||
name: LawnMowerMovingPLACEHOLDER_4
|
name: LawnMowerMovingPLACEHOLDER_4
|
||||||
rect:
|
rect:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 1239
|
x: 1238
|
||||||
y: 13
|
y: 13
|
||||||
width: 569
|
width: 575
|
||||||
height: 380
|
height: 384
|
||||||
alignment: 9
|
alignment: 9
|
||||||
pivot: {x: 0.5, y: 0.2}
|
pivot: {x: 0.5, y: 0.2}
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
@@ -258,9 +258,9 @@ TextureImporter:
|
|||||||
rect:
|
rect:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 1861
|
x: 1861
|
||||||
y: 12
|
y: 11
|
||||||
width: 569
|
width: 568
|
||||||
height: 380
|
height: 386
|
||||||
alignment: 9
|
alignment: 9
|
||||||
pivot: {x: 0.5, y: 0.2}
|
pivot: {x: 0.5, y: 0.2}
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
@@ -279,12 +279,12 @@ TextureImporter:
|
|||||||
name: LawnMowerMovingPLACEHOLDER_6
|
name: LawnMowerMovingPLACEHOLDER_6
|
||||||
rect:
|
rect:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 2242
|
x: 2243
|
||||||
y: 11
|
y: 10
|
||||||
width: 24
|
width: 24
|
||||||
height: 24
|
height: 26
|
||||||
alignment: 0
|
alignment: 9
|
||||||
pivot: {x: 0.5, y: 0.5}
|
pivot: {x: 0.5, y: 0.2}
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
customData:
|
customData:
|
||||||
outline: []
|
outline: []
|
||||||
@@ -309,7 +309,9 @@ TextureImporter:
|
|||||||
weights: []
|
weights: []
|
||||||
secondaryTextures: []
|
secondaryTextures: []
|
||||||
spriteCustomMetadata:
|
spriteCustomMetadata:
|
||||||
entries: []
|
entries:
|
||||||
|
- key: SpriteEditor.SliceSettings
|
||||||
|
value: '{"sliceOnImport":false,"gridCellCount":{"x":1.0,"y":1.0},"gridSpriteSize":{"x":100.0,"y":100.0},"gridSpriteOffset":{"x":0.0,"y":0.0},"gridSpritePadding":{"x":0.0,"y":0.0},"pivot":{"x":0.5,"y":0.20000000298023225},"autoSlicingMethod":0,"spriteAlignment":9,"slicingType":0,"keepEmptyRects":false,"isAlternate":false}'
|
||||||
nameFileIdTable:
|
nameFileIdTable:
|
||||||
LawnMowerMovingPLACEHOLDER_0: -4444670910754578914
|
LawnMowerMovingPLACEHOLDER_0: -4444670910754578914
|
||||||
LawnMowerMovingPLACEHOLDER_1: 6348190279078284696
|
LawnMowerMovingPLACEHOLDER_1: 6348190279078284696
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Pixelplacement
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Moves a Transform along a spline path from a start percentage to an end percentage.
|
/// Moves a Transform along a spline path from a start percentage to an end percentage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static TweenSystem.TweenBase Spline(Spline spline, Transform target, float startPercentage, float endPercentage, bool faceDirection, float duration, float delay, AnimationCurve easeCurve = null, LoopType loop = LoopType.None, Action startCallback = null, Action completeCallback = null, bool obeyTimescale = true)
|
public static TweenSystem.TweenBase Spline(Spline spline, Transform target, float startPercentage, float endPercentage, bool faceDirection, float duration, float delay, AnimationCurve easeCurve = null, LoopType loop = LoopType.None, Action startCallback = null, Action completeCallback = null, bool obeyTimescale = true, Action onComplete = null, Action onUpdate = null)
|
||||||
{
|
{
|
||||||
TweenSystem.SplinePercentage tween = new TweenSystem.SplinePercentage(spline, target, startPercentage, endPercentage, faceDirection, duration, delay, obeyTimescale, easeCurve, loop, startCallback, completeCallback);
|
TweenSystem.SplinePercentage tween = new TweenSystem.SplinePercentage(spline, target, startPercentage, endPercentage, faceDirection, duration, delay, obeyTimescale, easeCurve, loop, startCallback, completeCallback);
|
||||||
SendTweenForProcessing(tween, true);
|
SendTweenForProcessing(tween, true);
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ GameObject:
|
|||||||
- component: {fileID: 7695719922005140445}
|
- component: {fileID: 7695719922005140445}
|
||||||
- component: {fileID: 4901186366144297979}
|
- component: {fileID: 4901186366144297979}
|
||||||
- component: {fileID: 5264516637087018658}
|
- component: {fileID: 5264516637087018658}
|
||||||
- component: {fileID: 8801225172547510663}
|
|
||||||
m_Layer: 10
|
m_Layer: 10
|
||||||
m_Name: Lawnmower
|
m_Name: Lawnmower
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -233,6 +232,21 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 73d6494a73174ffabc6a7d3089d51e73, type: 3}
|
m_Script: {fileID: 11500000, guid: 73d6494a73174ffabc6a7d3089d51e73, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
isOneTime: 0
|
||||||
|
cooldown: -1
|
||||||
|
characterToInteract: 1
|
||||||
|
interactionStarted:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
interactionInterrupted:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
characterArrived:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
interactionComplete:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
--- !u!114 &5264516637087018658
|
--- !u!114 &5264516637087018658
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -246,15 +260,3 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
stepData: {fileID: 11400000, guid: ea383d1dee861f54c9a1d4f32a2f6afc, type: 2}
|
stepData: {fileID: 11400000, guid: ea383d1dee861f54c9a1d4f32a2f6afc, type: 2}
|
||||||
--- !u!114 &8801225172547510663
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 4940025602237181209}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 833a4ccef651449e973e623d9107bef5, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
|
|||||||
8
Assets/Scripts/DamianExperiments/Animations.meta
Normal file
8
Assets/Scripts/DamianExperiments/Animations.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c6fd0683cee159c4f899a794af80c7ce
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!74 &7400000
|
||||||
|
AnimationClip:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: LawnMowerMowing
|
||||||
|
serializedVersion: 7
|
||||||
|
m_Legacy: 0
|
||||||
|
m_Compressed: 0
|
||||||
|
m_UseHighQualityCurve: 1
|
||||||
|
m_RotationCurves: []
|
||||||
|
m_CompressedRotationCurves: []
|
||||||
|
m_EulerCurves: []
|
||||||
|
m_PositionCurves: []
|
||||||
|
m_ScaleCurves: []
|
||||||
|
m_FloatCurves: []
|
||||||
|
m_PPtrCurves:
|
||||||
|
- serializedVersion: 2
|
||||||
|
curve:
|
||||||
|
- time: 0
|
||||||
|
value: {fileID: -4444670910754578914, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- time: 0.18333334
|
||||||
|
value: {fileID: 5233908553689211412, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- time: 0.33333334
|
||||||
|
value: {fileID: 7052581180763600252, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- time: 0.48333332
|
||||||
|
value: {fileID: 4839952163610979709, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- time: 0.6666667
|
||||||
|
value: {fileID: -4444670910754578914, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
attribute: m_Sprite
|
||||||
|
path:
|
||||||
|
classID: 212
|
||||||
|
script: {fileID: 0}
|
||||||
|
flags: 2
|
||||||
|
m_SampleRate: 60
|
||||||
|
m_WrapMode: 0
|
||||||
|
m_Bounds:
|
||||||
|
m_Center: {x: 0, y: 0, z: 0}
|
||||||
|
m_Extent: {x: 0, y: 0, z: 0}
|
||||||
|
m_ClipBindingConstant:
|
||||||
|
genericBindings:
|
||||||
|
- serializedVersion: 2
|
||||||
|
path: 0
|
||||||
|
attribute: 0
|
||||||
|
script: {fileID: 0}
|
||||||
|
typeID: 212
|
||||||
|
customType: 23
|
||||||
|
isPPtrCurve: 1
|
||||||
|
isIntCurve: 0
|
||||||
|
isSerializeReferenceCurve: 0
|
||||||
|
pptrCurveMapping:
|
||||||
|
- {fileID: -4444670910754578914, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- {fileID: 5233908553689211412, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- {fileID: 7052581180763600252, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- {fileID: 4839952163610979709, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
- {fileID: -4444670910754578914, guid: 464f70d7647a22a4aa688ffc2b6654cc, type: 3}
|
||||||
|
m_AnimationClipSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_AdditiveReferencePoseClip: {fileID: 0}
|
||||||
|
m_AdditiveReferencePoseTime: 0
|
||||||
|
m_StartTime: 0
|
||||||
|
m_StopTime: 0.68333334
|
||||||
|
m_OrientationOffsetY: 0
|
||||||
|
m_Level: 0
|
||||||
|
m_CycleOffset: 0
|
||||||
|
m_HasAdditiveReferencePose: 0
|
||||||
|
m_LoopTime: 1
|
||||||
|
m_LoopBlend: 0
|
||||||
|
m_LoopBlendOrientation: 0
|
||||||
|
m_LoopBlendPositionY: 0
|
||||||
|
m_LoopBlendPositionXZ: 0
|
||||||
|
m_KeepOriginalOrientation: 0
|
||||||
|
m_KeepOriginalPositionY: 1
|
||||||
|
m_KeepOriginalPositionXZ: 0
|
||||||
|
m_HeightFromFeet: 0
|
||||||
|
m_Mirror: 0
|
||||||
|
m_EditorCurves: []
|
||||||
|
m_EulerEditorCurves: []
|
||||||
|
m_HasGenericRootTransform: 0
|
||||||
|
m_HasMotionFloatCurves: 0
|
||||||
|
m_Events: []
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 083a3166fef9168469713bd00eee5308
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 7400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1102 &-9094513822423650161
|
||||||
|
AnimatorState:
|
||||||
|
serializedVersion: 6
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: LawnMowerMowing
|
||||||
|
m_Speed: 1
|
||||||
|
m_CycleOffset: 0
|
||||||
|
m_Transitions: []
|
||||||
|
m_StateMachineBehaviours: []
|
||||||
|
m_Position: {x: 50, y: 50, z: 0}
|
||||||
|
m_IKOnFeet: 0
|
||||||
|
m_WriteDefaultValues: 1
|
||||||
|
m_Mirror: 0
|
||||||
|
m_SpeedParameterActive: 0
|
||||||
|
m_MirrorParameterActive: 0
|
||||||
|
m_CycleOffsetParameterActive: 0
|
||||||
|
m_TimeParameterActive: 0
|
||||||
|
m_Motion: {fileID: 7400000, guid: 083a3166fef9168469713bd00eee5308, type: 2}
|
||||||
|
m_Tag:
|
||||||
|
m_SpeedParameter:
|
||||||
|
m_MirrorParameter:
|
||||||
|
m_CycleOffsetParameter:
|
||||||
|
m_TimeParameter:
|
||||||
|
--- !u!1107 &-2429364330681070164
|
||||||
|
AnimatorStateMachine:
|
||||||
|
serializedVersion: 6
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Base Layer
|
||||||
|
m_ChildStates:
|
||||||
|
- serializedVersion: 1
|
||||||
|
m_State: {fileID: -9094513822423650161}
|
||||||
|
m_Position: {x: 30, y: 240, z: 0}
|
||||||
|
m_ChildStateMachines: []
|
||||||
|
m_AnyStateTransitions: []
|
||||||
|
m_EntryTransitions: []
|
||||||
|
m_StateMachineTransitions: {}
|
||||||
|
m_StateMachineBehaviours: []
|
||||||
|
m_AnyStatePosition: {x: 50, y: 20, z: 0}
|
||||||
|
m_EntryPosition: {x: 50, y: 120, z: 0}
|
||||||
|
m_ExitPosition: {x: 800, y: 120, z: 0}
|
||||||
|
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
|
||||||
|
m_DefaultState: {fileID: -9094513822423650161}
|
||||||
|
--- !u!91 &9100000
|
||||||
|
AnimatorController:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: _Lawnmower_Anim
|
||||||
|
serializedVersion: 5
|
||||||
|
m_AnimatorParameters: []
|
||||||
|
m_AnimatorLayers:
|
||||||
|
- serializedVersion: 5
|
||||||
|
m_Name: Base Layer
|
||||||
|
m_StateMachine: {fileID: -2429364330681070164}
|
||||||
|
m_Mask: {fileID: 0}
|
||||||
|
m_Motions: []
|
||||||
|
m_Behaviours: []
|
||||||
|
m_BlendingMode: 0
|
||||||
|
m_SyncedLayerIndex: -1
|
||||||
|
m_DefaultWeight: 0
|
||||||
|
m_IKPass: 0
|
||||||
|
m_SyncedLayerAffectsTiming: 0
|
||||||
|
m_Controller: {fileID: 9100000}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: be48400cf83222c49ba9d7b34ab1d9e4
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 9100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
29
Assets/Scripts/DamianExperiments/LawnMowerBehaviour.cs
Normal file
29
Assets/Scripts/DamianExperiments/LawnMowerBehaviour.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using Pixelplacement;
|
||||||
|
|
||||||
|
public class LawnMowerBehaviour : MonoBehaviour
|
||||||
|
{
|
||||||
|
private StateMachine stateMachineRef;
|
||||||
|
|
||||||
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
stateMachineRef = GetComponent<StateMachine>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public void mowerTouched()
|
||||||
|
{
|
||||||
|
Debug.Log("Mower Touched");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stateSwitch(string StateName)
|
||||||
|
{
|
||||||
|
Debug.Log("State Switch to: " + StateName);
|
||||||
|
stateMachineRef.ChangeState(StateName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9fba2c868971b20439aaea06a939d8e7
|
||||||
69
Assets/Scripts/DamianExperiments/LawnMowerChaseBehaviour.cs
Normal file
69
Assets/Scripts/DamianExperiments/LawnMowerChaseBehaviour.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using Pixelplacement;
|
||||||
|
|
||||||
|
public class LawnMowerChaseBehaviour : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Spline ChaseSpline;
|
||||||
|
public Transform LawnMowerObject;
|
||||||
|
public float chaseDuration;
|
||||||
|
public float chaseDelay;
|
||||||
|
|
||||||
|
private Vector3 _originalScale;
|
||||||
|
private bool _facingRight = true;
|
||||||
|
private bool _movingForward = true;
|
||||||
|
private float _lastPercentage = 0f;
|
||||||
|
private const float AnchorThreshold = 0.1f; // Tolerance for anchor detection
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
_originalScale = LawnMowerObject.localScale;
|
||||||
|
|
||||||
|
Tween.Spline(
|
||||||
|
ChaseSpline,
|
||||||
|
LawnMowerObject,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
chaseDuration,
|
||||||
|
chaseDelay,
|
||||||
|
Tween.EaseInOut,
|
||||||
|
Tween.LoopType.PingPong,
|
||||||
|
onComplete: OnTweenComplete
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTweenComplete()
|
||||||
|
{
|
||||||
|
_movingForward = !_movingForward;
|
||||||
|
Flip(_movingForward);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTweenUpdate()
|
||||||
|
{
|
||||||
|
// Find the current percentage along the spline
|
||||||
|
float percentage = ChaseSpline.ClosestPoint(LawnMowerObject.position);
|
||||||
|
|
||||||
|
// Detect anchor arrival and flip accordingly
|
||||||
|
if (_facingRight && percentage >= 1f - AnchorThreshold)
|
||||||
|
{
|
||||||
|
Flip(false); // Face left at end anchor
|
||||||
|
_facingRight = false;
|
||||||
|
}
|
||||||
|
else if (!_facingRight && percentage <= AnchorThreshold)
|
||||||
|
{
|
||||||
|
Flip(true); // Face right at start anchor
|
||||||
|
_facingRight = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastPercentage = percentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Flip(bool faceRight)
|
||||||
|
{
|
||||||
|
var scale = _originalScale;
|
||||||
|
scale.x = Mathf.Abs(scale.x) * (faceRight ? 1 : -1);
|
||||||
|
LawnMowerObject.localScale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() { }
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 426d4511f8eb64747ab44f61973dcf2e
|
||||||
Reference in New Issue
Block a user