Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Cinemachine;
- using UnityEngine.InputSystem;
- using UnityEngine.UI;
- using TMPro;
- using System.Globalization;
- //player - Singe Player (non multyplayer)
- public class PlayerSP : MonoBehaviour
- {
- //---- player Input System ----//
- private MyInputs
- myInputActions;
- private MyInputs
- myInputActionsGet
- {
- get
- {
- if (myInputActions != null)
- {
- return myInputActions;
- }
- return myInputActions = new MyInputs();
- }
- }
- //---- Player Movement ----//
- private float
- moveSpeed = 1.5f;
- //---- Player Chatercter Controller ----//
- private CharacterController
- myCharacterController;
- private float
- gravity = 8.5f;
- //---- Player Animations system ----//
- private Animator
- animator;
- void Awake()
- {
- animator = GetComponent<Animator>();
- myCharacterController = GetComponent<CharacterController>();
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- #region Input System
- //==== Input Sytem ====//
- public void PlayerInputSetup()
- {
- myInputActions = new MyInputs();
- myInputActions.Player.Enable();
- //myInputActionsGet.Player.Jump.performed += ctx => JumpButton();
- //myInputActionsGet.Player.Interact.performed += ctx => PickUpInteraction();
- //myInputActionsGet.Player.Fire.performed += ctx => SpawnCodePrefab(0);
- }
- private void OnEnable() => myInputActionsGet.Enable();
- private void OnDisable() => myInputActionsGet.Disable();
- #endregion
- // Update is called once per frame
- void Update()
- {
- PlayerMove();
- }
- //==== Player Movement ====//
- private void PlayerMove()
- {
- /*
- //old movemnet
- transform.Translate
- (
- 0,
- 0,
- myInputActions.Player.Move.ReadValue<Vector2>().y * Time.deltaTime * moveSpeed//_input.move.y
- );
- */
- //rotation
- transform.Rotate
- (
- 0,
- myInputActions.Player.Move.ReadValue<Vector2>().x * Time.deltaTime * 110.0f,// _input.move.x
- 0
- );
- //movement
- Vector3 moveDirection = transform.TransformDirection
- (
- 0,
- -gravity,
- myInputActions.Player.Move.ReadValue<Vector2>().y * moveSpeed
- );
- myCharacterController.Move(moveDirection * Time.deltaTime);
- //animation
- animator.SetFloat("Speed", myInputActions.Player.Move.ReadValue<Vector2>().y);
- }
- // See Order of Execution for Event Functions for information on FixedUpdate() and Update() related to physics queries
- void FixedUpdate()
- {
- // Bit shift the index of the layer (8) to get a bit mask
- int layerMask = 1 << 8;
- // This would cast rays only against colliders in layer 8.
- // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
- layerMask = ~layerMask;
- RaycastHit hit;
- Vector3 transformPosition = transform.position;
- Vector3 transformOffset = new Vector3
- (
- transformPosition.x,
- transformPosition.y + 1,
- transformPosition.z
- );
- // Does the ray intersect any objects excluding the player layer
- if (Physics.Raycast(transformPosition , transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
- {
- Debug.DrawRay(transformOffset , transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
- Debug.Log("Did Hit");
- }
- else
- {
- Debug.DrawRay(transformOffset , transform.TransformDirection(Vector3.forward) * 1000, Color.white);
- Debug.Log("Did not Hit");
- }
- }
- //==== FootSteps ====//
- public void OnFootstep()
- {
- //Do Nothing
- //I put this here because there is a function trigger in some of the animation and i dont feel like removing it from the aanimation
- //Debug.Log("Foot Step");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement