Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Movement : MonoBehaviour {
- public float speed;
- private bool collision;
- Rigidbody playerRigidbody;
- void Start() {
- playerRigidbody = GetComponent<Rigidbody>();
- }
- void Update() {
- playerRigidbody.velocity = Input.GetAxis("Horizontal") != 0 ?
- (new Vector3(Input.GetAxis("Horizontal") * speed, playerRigidbody.velocity.y))
- : new Vector3(0, playerRigidbody.velocity.y);
- //------------------------------------------------------------------------------------
- if (Input.GetButtonDown("Jump")) {
- transform.rotation = Quaternion.Euler(new Vector3((Physics.gravity.y < 0 ? 180 : 0), 0, 0));
- Physics.gravity = new Vector3(0, Physics.gravity.y * -1);
- }
- }
- void OnCollisionEnter(Collision collision) {
- switch (collision.gameobject.tag.ToLower()) {
- case "ground":
- colliding = true;
- break;
- case "saw":
- //die
- break;
- }
- }
- void OnCollisionStay(Collision collision) {
- switch (collision.gameobject.tag.ToLower()) {
- case "ground":
- colliding = true;
- break;
- case "saw":
- //die
- break;
- }
- }
- void OnCollisionExit(Collision collision) {
- switch (collision.gameobject.tag.ToLower()) {
- case "ground":
- colliding = false;
- break;
- case "saw":
- //die
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment