mirror of
https://github.com/ConjureETS/MeltedBananasOJam2016.git
synced 2026-03-24 02:21:06 +00:00
Finished implementation of Slowmo
This commit is contained in:
parent
2c70709305
commit
368ac6ef80
@ -1,33 +1,47 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PlayerMovement : MonoBehaviour {
|
||||
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
public float speed = 0f;
|
||||
public float turn = 0f;
|
||||
|
||||
public Rigidbody characterRigidBody;
|
||||
|
||||
// Boost
|
||||
public float boostFactor = 1f;
|
||||
public float seconds;
|
||||
float initialTime;
|
||||
float boostDeadline;
|
||||
bool SpeedBoostTimerStart;
|
||||
//private Rigidbody rb;
|
||||
// Slow motion
|
||||
public float timeFactor = 0.2f;
|
||||
public float duration = 5.0f;
|
||||
float slowmoDeadline;
|
||||
private bool SlowmoTimerStart = false;
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
SpeedBoostTimer(seconds);
|
||||
SlowmoTimer(duration);
|
||||
ManageMovement();
|
||||
}
|
||||
|
||||
private void ManageMovement()
|
||||
{
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
Vector3 fowardVector = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z);
|
||||
if (Input.GetAxis("Vertical")>0)
|
||||
if (Input.GetAxis("Vertical") > 0)
|
||||
{
|
||||
characterRigidBody.velocity = ( fowardVector * speed * boostFactor * Time.deltaTime);
|
||||
characterRigidBody.velocity = (fowardVector * speed * boostFactor * Time.deltaTime);
|
||||
}
|
||||
else if (Input.GetAxis("Vertical")<0)
|
||||
else if (Input.GetAxis("Vertical") < 0)
|
||||
{
|
||||
characterRigidBody.velocity = (-fowardVector * speed * boostFactor * Time.deltaTime);
|
||||
}
|
||||
if (Input.GetAxis("Horizontal")<0)
|
||||
if (Input.GetAxis("Horizontal") < 0)
|
||||
{
|
||||
characterRigidBody.velocity = (Vector3.Cross(-transform.up, fowardVector) * speed * boostFactor * Time.deltaTime);
|
||||
characterRigidBody.velocity = (Vector3.Cross(-transform.up, fowardVector) * speed * boostFactor * Time.deltaTime );
|
||||
}
|
||||
else if (Input.GetAxis("Horizontal") > 0)
|
||||
{
|
||||
@ -35,31 +49,46 @@ public class PlayerMovement : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
SpeedBoostTimer(seconds);
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider other)
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.tag == "SpeedBoost")
|
||||
{
|
||||
other.gameObject.SetActive (false);
|
||||
other.gameObject.SetActive(false);
|
||||
SpeedBoostTimerStart = true;
|
||||
}
|
||||
|
||||
if (other.gameObject.CompareTag("Slowmo"))
|
||||
{
|
||||
SlowmoTimerStart = true;
|
||||
other.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SpeedBoostTimer(float seconds)
|
||||
{
|
||||
if (SpeedBoostTimerStart)
|
||||
{
|
||||
boostFactor = 8f;
|
||||
initialTime = Time.realtimeSinceStartup + seconds;
|
||||
boostFactor = 8.0f;
|
||||
boostDeadline = Time.realtimeSinceStartup + seconds;
|
||||
SpeedBoostTimerStart = false;
|
||||
}
|
||||
if (Time.realtimeSinceStartup >= initialTime)
|
||||
if (Time.realtimeSinceStartup >= boostDeadline)
|
||||
{
|
||||
boostFactor = 1f;
|
||||
boostFactor = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
private void SlowmoTimer(float seconds)
|
||||
{
|
||||
if (SlowmoTimerStart)
|
||||
{
|
||||
TimeManager.SlowFactor = 0.2f;
|
||||
slowmoDeadline = Time.realtimeSinceStartup + seconds;
|
||||
SlowmoTimerStart = false;
|
||||
}
|
||||
if (Time.realtimeSinceStartup >= slowmoDeadline)
|
||||
{
|
||||
TimeManager.SlowFactor = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
Assets/Scripts/TimeManager.cs
Normal file
18
Assets/Scripts/TimeManager.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
public static class TimeManager
|
||||
{
|
||||
private static float slowFactor;
|
||||
public static float SlowFactor
|
||||
{
|
||||
get
|
||||
{
|
||||
return slowFactor;
|
||||
}
|
||||
set
|
||||
{
|
||||
slowFactor = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user