Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System.ComponentModel.DataAnnotations.Schema;
  2. using UnityEngine;
  3.  
  4. public class bewegung : MonoBehaviour
  5. {
  6.     public Rigidbody rb;
  7.  
  8.     public float Forward = 200f;
  9.     public float Left = 200f;
  10.     public float Right = 200f;
  11.     public float Backward = 200f;
  12.     public float Up = 10f;
  13.    
  14.  
  15.     void FixedUpdate()
  16.     {
  17.         switch (Mathf.RountToInt(Input.GetAxisRaw("Vertical")))
  18.         {
  19.             case -1:
  20.                 rb.AddForce(0, 0, Forward * Time.deltaTime, ForceMode.VelocityChange);
  21.                 break;
  22.            
  23.             case 1:
  24.                 rb.AddForce(0, 0, -Backward * Time.deltaTime, ForceMode.VelocityChange);
  25.                 break;
  26.         }
  27.  
  28.         switch (Mathf.RountToInt(Input.GetAxisRaw("Horizontal")))
  29.         {
  30.  
  31.             case -1:
  32.                 rb.AddForce(-Left * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  33.                 break;
  34.             case 1:
  35.                 rb.AddForce(Right * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  36.                 break;
  37.         }
  38.  
  39.         if (Input.GetKey("space"))
  40.             if (transform.position.y <=1.05)
  41.             {
  42.                 rb.AddForce(0, Up , 0, ForceMode.VelocityChange);
  43.             }
  44.  
  45.         if (rb.position.y < -5f)
  46.         {
  47.             FindObjectOfType<Gamemanager>().EndGame();
  48.         }
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement