From 326e76fd40ae57caec1cd3dc13205f28c40db756 Mon Sep 17 00:00:00 2001 From: karakune Date: Sat, 25 Jun 2016 18:47:10 -0400 Subject: [PATCH] =?UTF-8?q?ajout=20Boost=20de=20speed=20(ne=20pas=20prendr?= =?UTF-8?q?e=20classe=20enti=C3=A8re,=20juste=20partie=20pertinente)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/SpeedBoost.cs | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Assets/Scripts/SpeedBoost.cs diff --git a/Assets/Scripts/SpeedBoost.cs b/Assets/Scripts/SpeedBoost.cs new file mode 100644 index 0000000..dde355c --- /dev/null +++ b/Assets/Scripts/SpeedBoost.cs @@ -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; + } + + } +}