Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using ControlFreak2;
- public class PlayerController : MonoBehaviour
- {
- [Header("Player Options")]
- [Range(0, 100)] public float WalkSpeed;
- CharacterController cc;
- [Header("Rotate Camera Options")]
- public Camera cam;
- [Range(0, 200)] public float CameraSensibilidad;
- float vMouse;
- float hMouse;
- [Header("Fall Options")]
- [Range(0, 20)] public float SpeedControllerInFall;
- [Range(0, 20)] public float SmoothFallGravity;
- [Header("Check Ground Options")]
- public bool isGround;
- public Transform CheckFloor;
- [Range(0, 20)] public float CheckRadius;
- [Range(0, 500)] public float gravedad;
- public LayerMask mask;
- [Header("Extras Options")]
- public float SmoothTimeRotateLuz;
- public Transform Luz;
- void Start()
- {
- cc = GetComponent<CharacterController>();
- Application.targetFrameRate = 60;
- }
- void Update()
- {
- isGround = Physics.CheckSphere(CheckFloor.position, CheckRadius, mask);
- var h = CF2Input.GetAxis("Horizontal");
- var v = CF2Input.GetAxis("Vertical");
- Vector3 move = new Vector3(h, 0f, v);
- vMouse -= Time.deltaTime * CF2Input.GetAxis("Mouse Y") * 1 * CameraSensibilidad;
- hMouse += Time.deltaTime * CF2Input.GetAxis("Mouse X") * 1 * CameraSensibilidad;
- if (isGround)
- {
- this.transform.rotation = Quaternion.Euler(0f, hMouse, 0f);
- cam.transform.localEulerAngles = new Vector3(vMouse, 0f, 0f);
- move.y -= gravedad * Time.deltaTime * 1f;
- move = this.transform.TransformDirection(move);
- cc.Move(move * WalkSpeed * Time.deltaTime * 1);
- }
- else
- {
- this.transform.rotation = Quaternion.Euler(0f, hMouse, 0f);
- cam.transform.localEulerAngles = new Vector3(vMouse, 0f, 0f);
- move.y -= gravedad * Time.deltaTime * 1f / SmoothFallGravity;
- move = this.transform.TransformDirection(move / SpeedControllerInFall);
- cc.Move(move * WalkSpeed * Time.deltaTime * 1f);
- }
- }
- void OnDrawGizmos()
- {
- Gizmos.color = Color.yellow;
- Gizmos.DrawSphere(CheckFloor.position, CheckRadius);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement