Commit aabe5457 authored by Geri's avatar Geri
Browse files

Moving platforms

parent 4416f83b
Loading
Loading
Loading
Loading
+25 −28
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.41666666
        time: 0.4
        value: 0.78431374
        inSlope: 0
        outSlope: 0
@@ -48,7 +48,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.5833333
        time: 0.55
        value: 0.6862745
        inSlope: 0
        outSlope: 0
@@ -57,7 +57,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.8333333
        time: 0.75
        value: 0.78431374
        inSlope: 0
        outSlope: 0
@@ -66,7 +66,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.96666664
        time: 0.8833333
        value: 0.6862745
        inSlope: 0
        outSlope: 0
@@ -75,7 +75,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 1.0833334
        time: 1
        value: 0.78431374
        inSlope: 0
        outSlope: 0
@@ -121,7 +121,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.5833333
        time: 0.5
        value: 0.12
        inSlope: 0
        outSlope: 0
@@ -130,7 +130,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.8333333
        time: 0.75
        value: 0.17
        inSlope: 0
        outSlope: 0
@@ -139,7 +139,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.96666664
        time: 0.8833333
        value: 0.12
        inSlope: 0
        outSlope: 0
@@ -148,7 +148,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 1.0833334
        time: 1
        value: 0.17
        inSlope: 0
        outSlope: 0
@@ -178,20 +178,18 @@ AnimationClip:
    - time: 0.41666666
      value: {fileID: 326037436, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 0.5
      value: {fileID: 326037436, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 0.5833333
      value: {fileID: 650666326, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 0.6666667
    - time: 0.5833333
      value: {fileID: -699393054, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 0.75
    - time: 0.6666667
      value: {fileID: -1477147385, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 0.8333333
    - time: 0.75
      value: {fileID: -2035121808, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 0.9166667
    - time: 0.8333333
      value: {fileID: 2035472129, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 1
    - time: 0.9166667
      value: {fileID: 326037436, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - time: 1.0833334
    - time: 1
      value: {fileID: 326037436, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    attribute: m_Sprite
    path: 
@@ -232,7 +230,6 @@ AnimationClip:
    - {fileID: -2035121808, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - {fileID: 2035472129, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - {fileID: 326037436, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - {fileID: 326037436, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - {fileID: 650666326, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - {fileID: -699393054, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
    - {fileID: -1477147385, guid: cec81b6b093a89141be101aa1e1ced58, type: 3}
@@ -245,7 +242,7 @@ AnimationClip:
    m_AdditiveReferencePoseClip: {fileID: 0}
    m_AdditiveReferencePoseTime: 0
    m_StartTime: 0
    m_StopTime: 1.1
    m_StopTime: 1.0166667
    m_OrientationOffsetY: 0
    m_Level: 0
    m_CycleOffset: 0
@@ -283,7 +280,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.41666666
        time: 0.4
        value: 0.78431374
        inSlope: 0
        outSlope: 0
@@ -292,7 +289,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.5833333
        time: 0.55
        value: 0.6862745
        inSlope: 0
        outSlope: 0
@@ -301,7 +298,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.8333333
        time: 0.75
        value: 0.78431374
        inSlope: 0
        outSlope: 0
@@ -310,7 +307,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.96666664
        time: 0.8833333
        value: 0.6862745
        inSlope: 0
        outSlope: 0
@@ -319,7 +316,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 1.0833334
        time: 1
        value: 0.78431374
        inSlope: 0
        outSlope: 0
@@ -365,7 +362,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.5833333
        time: 0.5
        value: 0.12
        inSlope: 0
        outSlope: 0
@@ -374,7 +371,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.8333333
        time: 0.75
        value: 0.17
        inSlope: 0
        outSlope: 0
@@ -383,7 +380,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 0.96666664
        time: 0.8833333
        value: 0.12
        inSlope: 0
        outSlope: 0
@@ -392,7 +389,7 @@ AnimationClip:
        inWeight: 0.33333334
        outWeight: 0.33333334
      - serializedVersion: 3
        time: 1.0833334
        time: 1
        value: 0.17
        inSlope: 0
        outSlope: 0
+1309 −47

File changed.

Preview size limit exceeded, changes collapsed.

+8 −0
Original line number Diff line number Diff line
fileFormatVersion: 2
guid: 44220b25bc33a3749a7e073a9a9ba80c
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData: 
  assetBundleName: 
  assetBundleVariant: 
+58 −0
Original line number Diff line number Diff line
using System;
using System.Collections;
using System.Collections.Generic;
using SimpleTools;
using UnityEngine;

public class MovingPlatform : MonoBehaviour {

	[SerializeField] Vector2 endPosition;
	[SerializeField] float moveTime;
	[SerializeField] float stopDuration;

	Vector2 _start, _end;
	float _speed;

	Coroutine _swapRoutine;

	// Start is called before the first frame update
	void Awake() {
		_start = transform.position;
		_end = _start + endPosition;
		_speed = endPosition.magnitude / moveTime;
	}

	// Update is called once per frame
	void FixedUpdate() {
		StartCoroutine(FixedUpdateCoroutine());
	}

	IEnumerator FixedUpdateCoroutine() {
		yield return new WaitForFixedUpdate();
		transform.position = Vector3.MoveTowards(transform.position, _end, _speed * Time.deltaTime);

		if (Math.Abs(transform.position.sqrMagnitude - _end.sqrMagnitude) < 0.05f) {
			_swapRoutine ??= StartCoroutine(SwapCoordinates());
		}
	}

	IEnumerator SwapCoordinates() {
		yield return new WaitForSeconds(stopDuration);
		(_start, _end) = (_end, _start);
		_swapRoutine = null;
	}

	void OnTriggerEnter2D(Collider2D col) {
		if (col.CompareTag("Player")) col.transform.SetParent(transform);
	}
	void OnTriggerExit2D(Collider2D col) {
		if(col.CompareTag("Player")) col.transform.SetParent(null);
	}

	void OnDrawGizmos() {
		Gizmos.color = Color.green;
		Gizmos.DrawLine(transform.position, transform.position + (Vector3)endPosition);
		Gizmos.DrawSphere(transform.position, 0.25f);
		Gizmos.DrawSphere(transform.position + (Vector3)endPosition, 0.25f);
	}
}
+11 −0
Original line number Diff line number Diff line
fileFormatVersion: 2
guid: 9dd2f647ee7b470488f36b4c923f42e0
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 
Loading