mirror of
https://github.com/ConjureETS/MeltedBananasOJam2016.git
synced 2026-03-24 02:21:06 +00:00
Merge branch 'master' of https://github.com/ConjureETS/MeltedBananasOJam2016
This commit is contained in:
commit
4bcaefed86
68
Assets/Scripts/SpeedBoost.cs
Normal file
68
Assets/Scripts/SpeedBoost.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PlayerMovement : MonoBehaviour {
|
||||
|
||||
public float speed = 0f;
|
||||
public float turn = 0f;
|
||||
public float boostFactor = 1f;
|
||||
public float seconds;
|
||||
float initialTime;
|
||||
bool SpeedBoostTimerStart;
|
||||
public GameObject camera;
|
||||
public Rigidbody characterRigidBody;
|
||||
//private Rigidbody rb;
|
||||
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
Vector3 fowardVector = new Vector3(camera.transform.forward.x, 0, camera.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user