Updated collapsing platform script

This commit is contained in:
OverflowNarhoym 2022-02-25 11:32:01 +01:00
parent 9d748e44fc
commit 1aa1ef8251
2 changed files with 237 additions and 58 deletions

View File

@ -123,6 +123,153 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &387708699
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 387708701}
- component: {fileID: 387708700}
- component: {fileID: 387708703}
- component: {fileID: 387708702}
- component: {fileID: 387708704}
m_Layer: 3
m_Name: Collapsing_Platform_Small
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!212 &387708700
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 387708699}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!4 &387708701
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 387708699}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 12, y: -0.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1287783379}
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &387708702
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 387708699}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!50 &387708703
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 387708699}
m_BodyType: 2
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!114 &387708704
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 387708699}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5040194c42674482aab09aabcee0f9d4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &434782288
GameObject:
m_ObjectHideFlags: 0
@ -2383,6 +2530,53 @@ Transform:
m_CorrespondingSourceObject: {fileID: 7008207192594766311, guid: 2ed6bfce9ad3e19428cb9bef743e0fa3, type: 3}
m_PrefabInstance: {fileID: 7008207193554258683}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1287783378
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1287783379}
- component: {fileID: 1287783380}
m_Layer: 3
m_Name: CollapsingTriggerChecker
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1287783379
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1287783378}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.51, z: 0}
m_LocalScale: {x: 0.95, y: 0.05, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 387708701}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1287783380
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1287783378}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7000c8c0eb91b2d4cb9a0e3ee1b609a7, type: 3}
m_Name:
m_EditorClassIdentifier:
layerMask:
serializedVersion: 2
m_Bits: 4294966976
--- !u!1 &1524344315
GameObject:
m_ObjectHideFlags: 0
@ -2819,60 +3013,3 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ed6bfce9ad3e19428cb9bef743e0fa3, type: 3}
--- !u!1001 &7855840616584929621
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_RootOrder
value: 8
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalPosition.x
value: 10
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalPosition.y
value: -2.57
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350707, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7855840617602350708, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}
propertyPath: m_Name
value: Moving_Platform_Large
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c4ec2a2c5e627f04c9c647749966358d, type: 3}

View File

@ -1,9 +1,51 @@
using System.Collections;
using Movement;
using UnityEngine;
namespace Platforms
{
public class CollapsingPlatform : MonoBehaviour
{
private const float TimeBeforeCollapse = 2.0f;
private const float TimeBeforeReset = 4.0f;
private CollisionChecker _collidingTriggerCheck;
private bool _onCollision;
private void Awake()
{
_collidingTriggerCheck = GetComponentInChildren<CollisionChecker>();
}
private void Update()
{
if (!_collidingTriggerCheck.IsCollided || _onCollision) return;
Debug.Log("On collision");
_onCollision = true;
StartCoroutine(Collapse());
}
private void ChangeState(bool state)
{
GetComponent<SpriteRenderer>().enabled = state;
GetComponent<Collider2D>().enabled = state;
}
private IEnumerator Collapse()
{
//changer sprite en rouge
yield return new WaitForSeconds(TimeBeforeCollapse);
ChangeState(false);
StartCoroutine(Reset());
}
private IEnumerator Reset()
{
yield return new WaitForSeconds(TimeBeforeReset);
_onCollision = false;
//change sprite en normal
ChangeState(true);
}
}
}