mirror of
https://github.com/frizbee19/FebGameJam.git
synced 2026-09-11 08:17:01 +00:00
worked on platforms/moving platforms
This commit is contained in:
1 parent
cd92d52be2
commit
d10524a06a
7 files changed
+914
-11
No files matched your search
@@ -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:
|
||||
Reference in new issue
Block a user