mirror of
https://github.com/ConjureETS/MeltedBananasOJam2016.git
synced 2026-03-24 18:41:06 +00:00
66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class PlayerMovement : MonoBehaviour {
|
|
|
|
public float speed = 0f;
|
|
public float turn = 0f;
|
|
public Rigidbody characterRigidBody;
|
|
public float boostFactor = 1f;
|
|
public float seconds;
|
|
float initialTime;
|
|
bool SpeedBoostTimerStart;
|
|
//private Rigidbody rb;
|
|
|
|
|
|
|
|
// 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)
|
|
{
|
|
characterRigidBody.velocity = ( fowardVector * speed * boostFactor * Time.deltaTime);
|
|
}
|
|
else if (Input.GetAxis("Vertical")<0)
|
|
{
|
|
characterRigidBody.velocity = (-fowardVector * speed * boostFactor * Time.deltaTime);
|
|
}
|
|
if (Input.GetAxis("Horizontal")<0)
|
|
{
|
|
characterRigidBody.velocity = (Vector3.Cross(-transform.up, fowardVector) * speed * boostFactor * Time.deltaTime);
|
|
}
|
|
else if (Input.GetAxis("Horizontal") > 0)
|
|
{
|
|
characterRigidBody.velocity = (Vector3.Cross(transform.up, fowardVector) * speed * boostFactor * Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
SpeedBoostTimer(seconds);
|
|
}
|
|
|
|
void OnTriggerEnter (Collider other)
|
|
{
|
|
if (other.gameObject.tag == "SpeedBoost")
|
|
{
|
|
other.gameObject.SetActive (false);
|
|
SpeedBoostTimerStart = true;
|
|
}
|
|
}
|
|
|
|
private void SpeedBoostTimer(float seconds)
|
|
{
|
|
if (SpeedBoostTimerStart)
|
|
{
|
|
boostFactor = 8f;
|
|
initialTime = Time.realtimeSinceStartup + seconds;
|
|
SpeedBoostTimerStart = false;
|
|
}
|
|
if (Time.realtimeSinceStartup >= initialTime)
|
|
{
|
|
boostFactor = 1f;
|
|
}
|
|
}
|
|
}
|