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:
31
Assets/Scripts/FallPlatform.cs
Normal file
31
Assets/Scripts/FallPlatform.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/FallPlatform.cs.meta
Normal file
2
Assets/Scripts/FallPlatform.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d315bad368a8a247a5df8ac6b2f3ec1
|
||||
30
Assets/Scripts/MovingPlatform.cs
Normal file
30
Assets/Scripts/MovingPlatform.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MovingPlatform.cs.meta
Normal file
2
Assets/Scripts/MovingPlatform.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15a2da7226a2f054b9f96b2769e449e2
|
||||
28
Assets/Scripts/TeleportPlatform.cs
Normal file
28
Assets/Scripts/TeleportPlatform.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/TeleportPlatform.cs.meta
Normal file
2
Assets/Scripts/TeleportPlatform.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 182a9e619d36aeb4592fb532d3c9db55
|
||||
Reference in New Issue
Block a user