Add platform manager

This commit is contained in:
haitem
2022-01-29 01:19:21 +01:00
parent 423d7eef23
commit 142d0d0f52
6 changed files with 88 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlatformManager : MonoBehaviour
{
public enum PlatformType {Pull, Push, Rotate};
public PlatformType type = PlatformType.Pull;
void Start()
{
}
void FixedUpdate()
{
if (type == PlatformType.Rotate)
{
transform.Rotate(transform.forward);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fdc803964e5f2b042bece1765b69164f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -45,7 +45,7 @@ public class PlayerController : MonoBehaviour
moveDirection = (transform.forward * curSpeedX * Time.deltaTime) + (transform.right * curSpeedY * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isGoundet)
if (Input.GetKeyUp(KeyCode.Space) && isGoundet)
{
Debug.Log("Jump");
rb.AddForce(transform.up * jumpSpeed * 500 * Time.deltaTime, ForceMode.Impulse);
@@ -71,8 +71,15 @@ public class PlayerController : MonoBehaviour
angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up, -other.transform.up));
transform.RotateAround(axis, angle);
}
Vector3 gDirection = new Quaternion(0.0f, 0.0f, other.gameObject.transform.rotation.z, 1.0f) * Vector3.down;
Vector3 gDirection;
PlatformManager platform = other.gameObject.GetComponent<PlatformManager>();
if (platform != null && platform.type == PlatformManager.PlatformType.Pull) {
gDirection = new Quaternion(0.0f, 0.0f, other.gameObject.transform.rotation.z, 1.0f) * Vector3.down;
} else if (platform != null && platform.type == PlatformManager.PlatformType.Push) {
gDirection = new Quaternion(0.0f, 0.0f, other.gameObject.transform.rotation.z, 1.0f) * Vector3.up;
} else {
gDirection = new Quaternion(0.0f, 0.0f, other.gameObject.transform.rotation.z, 1.0f) * Vector3.down;
}
Physics.gravity = gDirection * 9.81f;
}