worked on platforms/moving platforms

This commit is contained in:
Rizvee committed 2022-02-24 18:50:19 -06:00
1 parent cd92d52be2
commit d10524a06a
7 files changed
+914 -11

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Platform : MonoBehaviour
{
public Vector3 positionToMoveTo;
public float length;
Vector3 startPos;
void Start()
{
startPos = transform.position;
StartCoroutine(LerpPosition(positionToMoveTo, length));
}
IEnumerator LerpPosition(Vector3 targetPosition, float duration)
{
float time = 0;
while (time < duration)
{
float t = time / duration;
t = t * t * (3f - 2f * t);
transform.position = Vector3.Lerp(startPos, targetPosition, t);
time += Time.deltaTime;
yield return null;
}
transform.position = targetPosition;
}
void Switch() {
Vector3 temp = startPos;
startPos = positionToMoveTo;
positionToMoveTo = temp;
}
// Update is called once per frame
void Update()
{
if(transform.position == positionToMoveTo) {
Switch();
StartCoroutine(LerpPosition(positionToMoveTo, length));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 56977ce248620a94199b7ddedef0152e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: