SebastianLawe

Untitled

Apr 17th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Movement : MonoBehaviour {
  5.  
  6.     public float speed;
  7.     private bool collision;
  8.     Rigidbody playerRigidbody;
  9.  
  10.     void Start() {
  11.         playerRigidbody = GetComponent<Rigidbody>();
  12.     }
  13.     void Update() {
  14.         playerRigidbody.velocity = Input.GetAxis("Horizontal") != 0 ?
  15.             (new Vector3(Input.GetAxis("Horizontal") * speed, playerRigidbody.velocity.y))
  16.             : new Vector3(0, playerRigidbody.velocity.y);
  17.         //------------------------------------------------------------------------------------
  18.         if (Input.GetButtonDown("Jump")) {
  19.             transform.rotation = Quaternion.Euler(new Vector3((Physics.gravity.y < 0 ? 180 : 0), 0, 0));
  20.             Physics.gravity = new Vector3(0, Physics.gravity.y * -1);
  21.         }
  22.     }
  23.     void OnCollisionEnter(Collision collision) {
  24.         switch (collision.gameobject.tag.ToLower()) {
  25.             case "ground":
  26.                 colliding = true;
  27.                 break;
  28.             case "saw":
  29.                 //die
  30.                 break;
  31.         }
  32.     }
  33.     void OnCollisionStay(Collision collision) {
  34.         switch (collision.gameobject.tag.ToLower()) {
  35.             case "ground":
  36.                 colliding = true;
  37.                 break;
  38.             case "saw":
  39.                 //die
  40.                 break;
  41.         }
  42.     }
  43.     void OnCollisionExit(Collision collision) {
  44.         switch (collision.gameobject.tag.ToLower()) {
  45.             case "ground":
  46.                 colliding = false;
  47.                 break;
  48.             case "saw":
  49.                 //die
  50.                 break;
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment