Advertisement
Guest User

Script

a guest
Dec 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4.  
  5. public class UnityMover : MonoBehaviour
  6.  
  7.  
  8.     {
  9.     public float speed = 6.0F;
  10.     public float jumpSpeed = 8.0F;
  11.     public float gravity = 20.0F;
  12.     public Rigidbody rb;
  13.  
  14.     public float groundCheckRadius;
  15.     public Transform groundCheck;
  16.     public LayerMask whatIsGround;
  17.  
  18.  
  19.  
  20.     private bool Grounded;
  21.  
  22.     private Vector3 moveDirection = Vector3.zero;
  23.     void Update() {
  24.         CharacterController controller = GetComponent<CharacterController>();
  25.         if (controller.isGrounded || !Grounded)
  26.         {
  27.             moveDirection = new Vector3 (Input.GetAxis("Horizontal"), velocity.y, 0);
  28.             moveDirection = transform.TransformDirection(moveDirection);
  29.             moveDirection *= speed;
  30.  
  31.             }
  32.  
  33.  
  34.         if (Input.GetKeyDown(KeyCode.Space) && Grounded)
  35.         {
  36.                 moveDirection.y = jumpSpeed;
  37.  
  38.         }
  39.         moveDirection.y -= gravity * Time.deltaTime;
  40.         controller.Move(moveDirection * Time.deltaTime);
  41.     }
  42.  
  43.     void FixedUpdate()
  44.         {
  45.             Grounded = Physics.OverlapSphere (groundCheck.position, groundCheckRadius, whatIsGround).Length > 0;
  46.  
  47.  
  48.  
  49.             /*
  50.             if ((Mathf.Abs (input.x) > float.Epsilon || Mathf.Abs (input.y) > float.Epsilon) && (advancedSettings.airControl || m_IsGrounded)) {
  51.                 // always move along the camera forward as it is the direction that it being aimed at
  52.  
  53.                 desiredMove = Vector3.ProjectOnPlane (desiredMove, m_GroundContactNormal).normalized;
  54.  
  55.                 desiredMove.x = desiredMove.x * movementSettings.CurrentTargetSpeed;
  56.                 desiredMove.y = desiredMove.y * movementSettings.CurrentTargetSpeed;
  57.                 if (m_RigidBody.velocity.sqrMagnitude <
  58.                    (movementSettings.CurrentTargetSpeed * movementSettings.CurrentTargetSpeed)) {
  59.                     rb.AddForce (desiredMove * SlopeMultiplier (), ForceMode.Impulse);
  60.                 }*/
  61.             }
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement