The_Riddle_Man

Untitled

Jun 5th, 2021
640
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class playerControler : MonoBehaviour
  7. {
  8.     public Rigidbody rigidbody;
  9.     public float force;
  10.     public float cforce;
  11.     public float saut;
  12.     public Animator  animator;
  13.  
  14.     private void Start() {
  15.         Time.timeScale = 1f;
  16.         Time.fixedDeltaTime = 0.02f * Time.timeScale;
  17.     }
  18.  
  19.     private void FixedUpdate()
  20.     {
  21.         rigidbody.AddForce(0, 0, force * Time.deltaTime);
  22.  
  23.         if (Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.LeftArrow)) {
  24.             rigidbody.AddForce(-cforce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  25.  
  26.         } else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) {
  27.             rigidbody.AddForce(cforce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  28.  
  29.         } else if (Input.GetKeyDown(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow)); {
  30.             rigidbody.AddForce(0, saut * Time.deltaTime, 0, ForceMode.VelocityChange);
  31.         }
  32.  
  33.         if (Input.GetKey(KeyCode.R)) ; animator.SetTrigger("Gameover"){
  34.             StartCoroutine(RestartLevel());
  35.         }
  36.     }
  37.  
  38.     private void OnCollisionEnter(Collision other) {
  39.         if(other.collider.tag == "obstacle"){
  40.             StartCoroutine(GameOver());
  41.         }
  42.     }
  43.  
  44.     public IEnumerator RestartLevel(){
  45.         yield return new WaitForSeconds(0.6f);
  46.         SceneManager.LoadScene("SampleScene");
  47.     }
  48.  
  49.  
  50.     public IEnumerator GameOver(){
  51.         Time.timeScale=0.3f;
  52.         Time.fixedDeltaTime=0.02f*Time.timeScale;
  53.         this.enabled=false;
  54.         animator.SetTrigger("Gameover");
  55.         yield return new WaitForSeconds(0.6f);
  56.         SceneManager.LoadScene("SampleScene");
  57.     }
RAW Paste Data