mirror of
https://github.com/frizbee19/FebGameJam.git
synced 2026-10-11 18:19:11 +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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user