Advertisement
Dieton

BasicInputSystem

May 18th, 2023 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem;
  5.  
  6. [RequireComponent(typeof(Rigidbody))]
  7. public class BasicInputSystem: MonoBehaviour
  8. {
  9.  
  10.     // -- Animation --//
  11.     public Animator animator;  
  12.  
  13.     //-- Input Variables --//
  14.     private PlayerInput playerInput;// third person player input clone
  15.     private MyInputActionControls myInputActions;//this comes from creating playerInput Script
  16.  
  17.     // Start is called before the first frame update
  18.     void Start()
  19.     {
  20.         PlayerInputSetup();
  21.     }
  22.    
  23.     //==== Input Sytem ====//
  24.     public void PlayerInputSetup()
  25.     {
  26.         playerInput = GetComponent<PlayerInput>();
  27.         myInputActions = new MyInputActionControls();
  28.         myInputActions.Player.Enable();
  29.     }
  30.  
  31.     // Update is called once per frame
  32.     void Update()
  33.     {
  34.         PlayerMove();
  35.     }
  36.  
  37.     //==== Player Move ====//
  38.     public void PlayerMove()
  39.     {
  40.         PlayerMovementInputVector = myInputActions.Player.Move.ReadValue<Vector2>();
  41.         moveX = PlayerMovementInputVector.x * Time.deltaTime * 110.0f;// _input.move.x
  42.         moveZ = PlayerMovementInputVector.y * Time.deltaTime * playerMoveSpeed;//_input.move.y
  43.         transform.Translate(0, 0, moveZ);
  44.         transform.Rotate(0, moveX, 0);
  45.  
  46.         if (isLocalPlayer)
  47.         {
  48.             animator.SetFloat("Speed", PlayerMovementInputVector.y);
  49.         }
  50.     }
  51. }
  52.  
Tags: Unity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement