2022-01-29 00:19:21 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class PlatformManager : MonoBehaviour
|
|
|
|
{
|
2022-01-29 19:12:11 +00:00
|
|
|
public enum PlatformType {Basic, Pull, Push, RotateZ, RotateY, SpeedUp, SpeedDown};
|
2022-01-29 00:19:21 +00:00
|
|
|
public PlatformType type = PlatformType.Pull;
|
2022-01-29 02:25:16 +00:00
|
|
|
public float speed = 5;
|
2022-01-30 02:17:17 +00:00
|
|
|
public AudioSource audioSource;
|
|
|
|
public List<AudioClip> audioClips = new List<AudioClip>();
|
2022-01-29 00:19:21 +00:00
|
|
|
|
|
|
|
void FixedUpdate()
|
|
|
|
{
|
2022-01-29 00:47:41 +00:00
|
|
|
if (type == PlatformType.RotateZ)
|
2022-01-29 00:19:21 +00:00
|
|
|
{
|
2022-01-29 02:25:16 +00:00
|
|
|
transform.Rotate(transform.forward * speed * Time.deltaTime);
|
2022-01-29 00:47:41 +00:00
|
|
|
} else if (type == PlatformType.RotateY) {
|
2022-01-29 02:25:16 +00:00
|
|
|
transform.Rotate(transform.up * speed * Time.deltaTime);
|
2022-01-29 00:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-30 02:17:17 +00:00
|
|
|
|
|
|
|
public void Step()
|
|
|
|
{
|
|
|
|
if (audioSource != null && audioClips.Count > 0 && !audioSource.isPlaying)
|
|
|
|
{
|
|
|
|
audioSource.PlayOneShot(audioClips[Random.Range(0, audioClips.Count)]);
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 22:01:17 +00:00
|
|
|
|
|
|
|
public void Action(PlayerController player, string status)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PlatformType.Basic:
|
|
|
|
return;
|
|
|
|
case PlatformType.Pull:
|
2022-02-02 21:30:51 +00:00
|
|
|
if (status == "stay")
|
2022-02-01 22:01:17 +00:00
|
|
|
{
|
2022-02-02 21:30:51 +00:00
|
|
|
player.jumpModifier = -speed / 10f;
|
|
|
|
}
|
|
|
|
else if (status == "exit")
|
|
|
|
{
|
|
|
|
player.jumpModifier = 0f;
|
2022-02-01 22:01:17 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case PlatformType.Push:
|
2022-02-02 21:30:51 +00:00
|
|
|
if (status == "stay")
|
|
|
|
{
|
|
|
|
player.jumpModifier = speed / 10f;
|
|
|
|
}
|
|
|
|
else if (status == "exit")
|
2022-02-01 22:01:17 +00:00
|
|
|
{
|
2022-02-02 21:30:51 +00:00
|
|
|
player.jumpModifier = 0f;
|
2022-02-01 22:01:17 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case PlatformType.RotateY:
|
|
|
|
return;
|
|
|
|
case PlatformType.RotateZ:
|
|
|
|
return;
|
|
|
|
case PlatformType.SpeedDown:
|
|
|
|
if (status == "enter")
|
|
|
|
{
|
|
|
|
if (player.speedModifier - speed >= 0)
|
|
|
|
{
|
|
|
|
player.speedModifier -= speed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player.speedModifier = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case PlatformType.SpeedUp:
|
|
|
|
if (status == "enter")
|
|
|
|
{
|
|
|
|
player.speedModifier += speed;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-01-29 00:19:21 +00:00
|
|
|
}
|