- Home /
Question by
Gabimela · Oct 10, 2020 at 08:50 PM ·
unity 5scripting problem3dcontrollerplaystation
Trying to switch over to the new input system
So i have recently installed the new input system package and i am trying to use my ps4 controller to get the player to shoot. I have a seperate script called Gun which has code for shoot and reload. I am trying to get the shoot to work when the player presses R2 on the controller.
here is my code:
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMove : MonoBehaviour
{
Ps4Controls control;
Vector3 move; //movement on x and y
void Awake()
{
control = new Ps4Controls();
control.GamePlay.PlayerMove.performed += ctx => move = ctx.ReadValue<Vector2>();
control.GamePlay.PlayerMove.canceled += ctx => move = Vector3.zero;
control.GamePlay.Shoot.performed += ctx =>shoot();
}
void Update()
{
transform.position += new Vector3(move.x * Time.deltaTime, 0, move.y * Time.deltaTime);
}
void shoot()
{
GetComponent<Gun>().Shoot();
GetComponent<Gun>().AmmoDecrease(1);
}
void OnEnable()
{
control.GamePlay.Enable();
}
void OnDisable()
{
control.GamePlay.Disable();
}
}
Comment
Your answer
Follow this Question
Related Questions
Script on multiple objects not working properly! 1 Answer
How can i look for collisions of the bulidngs in may array ? how can i use OnTRiggerEnter/exit ? 0 Answers
Is it possible to access the speaker in the DualShock 4 controller without the PS4 kit? 1 Answer
How to Set Animation Position on Slope (animation) help please 1 Answer
How would you be able to make dry patches apear and if it rains it would make them grassy again? 1 Answer