Advertisement
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;
- public bool IsCrouching;
- public bool IsPressedS;
- private Player acPlayer;
- private Char character;
- Animation camAnim;
- Animation acPlayerAnim;
- Animator animator;
- CapsuleCollider col;
- Camera playerCam;
- Quaternion playerAngle_180 = Quaternion.Euler (0, 180, 0);
- Quaternion playerAngle_0 = Quaternion.Euler(0, 0, 0);
- Quaternion currentAngle;
- private void Start()
- {
- rb = GetComponent<Rigidbody>();
- animator = GetComponent<Animator>();
- col = GetComponent<CapsuleCollider>();
- camAnim = GetComponentInChildren<Animation>();
- acPlayer = GetComponent<AC.Player>();
- character = GetComponent<AC.Char>();
- IsCrouching = false;
- IsPressedS = false;
- currentAngle = playerAngle_0;
- }
- #region abilita lo script AC motion control solo per posizionare il player in direzione della freccia, dopodichè lo disabilita per sfruttare il custom controller
- /*
- StartCoroutine(PlayerAutomatic());
- {
- IEnumerator PlayerAutomatic()
- {
- acPlayer.motionControl = AC.MotionControl.Automatic;
- yield return new WaitForSeconds(0.1f);
- acPlayer.motionControl = AC.MotionControl.Manual;
- }
- }
- */
- #endregion
- private void LateUpdate()
- {
- #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;
- }
- #endregion
- #region controlla se il il pulsante S è premuto, se si, in combinazione con LeftAlt ruota il player 180 gradi, se invece S viene rilasciato non fa niente.
- if (IsCrouching == false && (IsPressedS == false) && Input.GetKey(KeyCode.S))
- {
- IsPressedS = true;
- character.runSpeedScale = 2f;
- }
- else if (IsPressedS == true && Input.GetKeyUp(KeyCode.S))
- {
- IsPressedS = false;
- character.runSpeedScale = 4f;
- }
- if (IsCrouching == false && (IsPressedS == true) && Input.GetKeyDown(KeyCode.LeftAlt))
- {
- {
- changeCurrentAngle();
- }
- acPlayer.transform.localRotation = Quaternion.Lerp(playerAngle_0, playerAngle_180, 0.1f);
- }
- void changeCurrentAngle ()
- {
- if (currentAngle.eulerAngles.y == playerAngle_0.eulerAngles.y)
- acPlayer.SetRotation (playerAngle_180);
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement