Added moving and teleporting platforms in ObstanceWIP. Falling Platform is a WIP

Falling Platforms don't work yet. Still haven't figured out how to make it fall
This commit is contained in:
TGall8
2025-02-28 17:46:02 -05:00
parent 189aab2fd8
commit 8543734eb9
10 changed files with 1223 additions and 88 deletions

View File

@@ -0,0 +1,31 @@
using System.Collections;
using UnityEngine;
public class FallPlatform : MonoBehaviour
{
public float fallDelay = 2f;
public float destroyDelay = 2f;
bool falling;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void OnCollisionEnter2D(Collider2D collision)
{
if (!falling && collision.gameObject.CompareTag("Player"))
{
StartCoroutine(FallAfterDelay());
}
}
private IEnumerator FallAfterDelay()
{
falling = true;
yield return new WaitForSeconds(fallDelay);
rb.bodyType = RigidbodyType2D.Dynamic;
Destroy(gameObject, destroyDelay);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6d315bad368a8a247a5df8ac6b2f3ec1

View File

@@ -0,0 +1,30 @@
using UnityEngine;
public class MovingPlatform : MonoBehaviour
{
public Transform platform;
public int startPoint;
public Transform[] points;
public float speed;
private int i;
void Start()
{
transform.position = points[startPoint].position;
}
void Update()
{
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
{
i++;
if (i == points.Length)
{
i = 0;
}
}
transform.position = Vector2.MoveTowards(transform.position, points[i].position, speed * Time.deltaTime);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 15a2da7226a2f054b9f96b2769e449e2

View File

@@ -0,0 +1,28 @@
using UnityEngine;
public class TeleportPlatform : MonoBehaviour
{
public Vector2 teleportPoint;
//public bool teleportPosition = false;
public string teleportTag;
//private void Start()
//{
//if (teleportPosition)
//{
//teleportPoint = transform.position;
//}
//}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag(teleportTag))
{
transform.position = teleportPoint;
if (TryGetComponent<Rigidbody2D>(out var rb))
{
rb.linearVelocity = Vector2.zero;
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 182a9e619d36aeb4592fb532d3c9db55