Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using AC;
- public class ControllerPlayer : MonoBehaviour
- {
- Rigidbody rb;
- private float speed = 40f;
- private float rotationSpeed = 50f;
- public bool IsCrouching;
- public bool IsPressedS;
- private Player acPlayer;
- private Char character;
- Animation camAnim;
- Animator animator;
- CapsuleCollider col;
- Camera playerCam;
- private float speedRotation = 1f;
- public void Start ()
- {
- rb = GetComponent<Rigidbody>();
- animator = GetComponent<Animator>();
- //controller = GetComponent<CharacterController>();
- col = GetComponent<CapsuleCollider>();
- playerCam = GetComponentInChildren<Camera>();
- camAnim = GetComponentInChildren<Animation>();
- acPlayer = GetComponent<AC.Player>();
- character = GetComponent<AC.Char>();
- IsCrouching = false;
- IsPressedS = false;
- //StartCoroutine(PlayerAutomatic());
- }
- /*IEnumerator PlayerAutomatic()
- {
- AC.KickStarter.player.motionControl = AC.MotionControl.Automatic;
- yield return new WaitForSeconds(0.1f);
- AC.KickStarter.player.motionControl = AC.MotionControl.Manual;
- }
- */
- public void LateUpdate()
- #region Movimento fuori da AC - sennΓ² utilizza AC solo per vertical e horizontal
- {
- float translation = Input.GetAxis("Vertical") * speed;
- float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
- translation *= speed * Time.deltaTime;
- rotation *= rotationSpeed * Time.deltaTime;
- Quaternion turn = Quaternion.Euler(0f, rotation, 0f);
- rb.MoveRotation(rb.rotation * turn);
- animator.SetFloat("vertical", translation, 0.1f, Time.deltaTime * 10);
- animator.SetFloat("horizontal", rotation, 0.1f, Time.deltaTime * 10);
- #endregion
- #region attiva crouch + modifica dimensione collider + modifica posizione camera + modifica velocitΓ corsa
- if (IsCrouching == false && Input.GetKeyDown(KeyCode.C))
- {
- animator.SetBool("crouch", true);
- IsCrouching = true;
- col.height = 1.1f;
- col.center = new Vector3(0f, 0.5f, 0f);
- camAnim.Play("CamAnimDown");
- character.runSpeedScale = 2f;
- character.walkSpeedScale = 1f;
- }
- else if (IsCrouching == true && Input.GetKeyDown(KeyCode.C))
- {
- animator.SetBool("crouch", false);
- IsCrouching = false;
- col.height = 1.58f;
- col.center = new Vector3(0f, 0.77f, 0f);
- camAnim.Play("CamAnimUp");
- character.runSpeedScale = 4f;
- character.walkSpeedScale = 2f;
- }
- if (IsCrouching == false && (IsPressedS == false) && Input.GetKey(KeyCode.S))
- {
- IsPressedS = true;
- character.runSpeedScale = 2f;
- character.walkSpeedScale = 1f;
- }
- else if (IsPressedS == true && Input.GetKeyUp(KeyCode.S))
- {
- IsPressedS = false;
- character.runSpeedScale = 4f;
- character.walkSpeedScale = 2f;
- }
- if (IsCrouching == false && (IsPressedS == true) && Input.GetKeyDown(KeyCode.LeftAlt))
- {
- this.transform.Rotate(0, 180 * Time.deltaTime, 0, Space.Self);
- }
- #endregion
- }
- }
- /*
- this.transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, 0), speedRotation * Time.deltaTime);
- */
Advertisement
Add Comment
Please, Sign In to add comment