Updated moving platform script

This commit is contained in:
OverflowNarhoym 2022-02-23 13:05:30 +01:00
parent 2ab3a57899
commit ff14aea8b2
2 changed files with 185 additions and 5 deletions

View File

@ -2378,6 +2378,154 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 85e13cc38c9c13145bdb0c612c6e2cbe, type: 3}
--- !u!1 &597989745
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 597989749}
- component: {fileID: 597989748}
- component: {fileID: 597989747}
- component: {fileID: 597989746}
- component: {fileID: 597989750}
m_Layer: 0
m_Name: Square
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!61 &597989746
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 597989745}
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 &597989747
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 597989745}
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: 7
--- !u!212 &597989748
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 597989745}
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 &597989749
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 597989745}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 7.49, y: -2.68, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &597989750
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 597989745}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1637c8c06cf9fae4eb7bfa1a0ebb0e55, type: 3}
m_Name:
m_EditorClassIdentifier:
xOffeset: 20
yOffset: 0
--- !u!4 &1053905692 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7008207192594766311, guid: 2ed6bfce9ad3e19428cb9bef743e0fa3, type: 3}
@ -2761,6 +2909,14 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 698768805, guid: 2ed6bfce9ad3e19428cb9bef743e0fa3, type: 3}
propertyPath: m_LocalScale.y
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 2083070161, guid: 2ed6bfce9ad3e19428cb9bef743e0fa3, type: 3}
propertyPath: m_LocalScale.y
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 7008207192594766305, guid: 2ed6bfce9ad3e19428cb9bef743e0fa3, type: 3}
propertyPath: m_Name
value: Player

View File

@ -5,25 +5,49 @@ namespace Platforms
{
public class MovingPlatform : MonoBehaviour, IMovement
{
public float xOffeset;
public float yOffset;
private Rigidbody2D _platformRigidbody;
private Vector3 _velocity = Vector3.zero;
private void Awake()
{
_platformRigidbody = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
if (!IsPaused)
Move(BaseSpeed);
}
// PAUSING METHODS
public bool IsPaused { get; }
public bool IsPaused { get; private set; }
public void Pause()
{
throw new System.NotImplementedException();
IsPaused = true;
_platformRigidbody.simulated = !IsPaused;
}
public void Resume()
{
throw new System.NotImplementedException();
IsPaused = false;
_platformRigidbody.simulated = !IsPaused;
}
// MOVEMENT METHODS
public float BaseSpeed { get; set; }
public void Move(float value)
{
throw new System.NotImplementedException();
var position = transform.position;
var targetPosition = new Vector3(position.x + xOffeset, position.y + yOffset, 0.0f);
position = Vector3.SmoothDamp(position, targetPosition, ref _velocity, 1.0f);
transform.position = position;
}
}
}
}