Advertisement
Guest User

Untitled

a guest
Jun 11th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Movement_Player : MonoBehaviour
  6. {
  7.    
  8.     [Header("States (?)")]
  9.     public HoC_Input Controls;
  10.     [SerializeField] private bool isSprinting = false;
  11.     [SerializeField] private Vector2 curDir;
  12.  
  13.     private void Awake()
  14.     {
  15.         Controls = new HoC_Input();
  16.        
  17.         //Movement
  18.         Controls.Player.Move.performed += ctxCurDir => curDir = ctxCurDir.ReadValue<Vector2>();
  19.         Controls.Player.Move.performed += ctxMove => Move(ctxMove.ReadValue<Vector2>());
  20.  
  21.     }
  22.     private void OnEnable()
  23.     {
  24.         Controls.Enable();
  25.     }
  26.     private void OnDisable()
  27.     {
  28.         Controls.Disable();
  29.     }
  30.  
  31.     [Header("Stats")]
  32.     public float Speed = 5;
  33.     public float SprintSpeed = 7.5f;
  34.  
  35.     private void Move(Vector2 dir)
  36.     {
  37.         gameObject.transform.position += (new Vector3(dir.x, 0, dir.y) * (isSprinting ? SprintSpeed : Speed)) * Time.fixedDeltaTime;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement