Slide and Glide
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float basespeed;
|
||||
[SerializeField] private float speed;
|
||||
[SerializeField] private Rigidbody rb;
|
||||
[SerializeField] private float speedincrease;
|
||||
private Rigidbody rb;
|
||||
[SerializeField] private Vector3 StartPos;
|
||||
[SerializeField] private float slide;
|
||||
|
||||
Vector3 moveDirection;
|
||||
|
||||
bool vertical;
|
||||
bool horizontal;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
@@ -21,26 +28,38 @@ public class PlayerMove : MonoBehaviour
|
||||
horizontalInput = Mathf.Round(horizontalInput);
|
||||
verticalInput = Mathf.Round(verticalInput);
|
||||
|
||||
Vector3 moveDirection;
|
||||
|
||||
|
||||
if (horizontalInput != 0 && horizontal == true)
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(0f, 0f, 90f);
|
||||
vertical = false;
|
||||
moveDirection = new Vector3(horizontalInput,0, 0);
|
||||
moveDirection.Normalize();
|
||||
|
||||
if (!vertical)
|
||||
{
|
||||
speed += speedincrease;
|
||||
}
|
||||
|
||||
}
|
||||
else if (verticalInput != 0 && vertical == true)
|
||||
{
|
||||
transform.rotation = Quaternion.Euler(90f, 0f, 0f);
|
||||
horizontal = false;
|
||||
moveDirection = new Vector3(0, 0, verticalInput);
|
||||
moveDirection.Normalize();
|
||||
|
||||
if (!horizontal)
|
||||
{
|
||||
speed += speedincrease;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
moveDirection = new Vector3(0, 0, 0);
|
||||
horizontal = true;
|
||||
vertical = true;
|
||||
StartCoroutine(Slide(slide));
|
||||
transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -52,4 +71,14 @@ public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
this.transform.position = StartPos;
|
||||
}
|
||||
|
||||
IEnumerator Slide(float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
moveDirection = new Vector3(0, 0, 0);
|
||||
horizontal = true;
|
||||
vertical = true;
|
||||
speed = basespeed;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user