- Home /
Not sure how to change script to work with newer input system
Hi, i've just managed to change my movement system to work with the newer movement system (despite not really understanding it) and i'm now trying to get shooting working, however I dont seem to be able to get it to work using any of the methods I have seen. any help would be greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class WeaponFireProjectile : MonoBehaviour
{
PlayerControls controls;
public Transform firepoint;
public GameObject projectile;
private float firepersec;
public float starttimebtwnshots;
//Overlap Detection
public Transform Basepoint;
Vector2 firstpos;
Vector2 secpos;
public LayerMask whatisGround;
bool overlapping;
void Awake()
{
controls.Gameplay.Shoot.performed += ctx => Shoot();
}
void Update()
{
firstpos = new Vector2 (firepoint.position.x, firepoint.position.y);
secpos = new Vector2(Basepoint.position.x, Basepoint.position.y);
overlapping = Physics2D.OverlapArea(firstpos, secpos, whatisGround);
}
void Shoot()
{
if (firepersec <= 0)
{
if (!overlapping)
{
Instantiate(projectile, firepoint.position, transform.rotation * Quaternion.Euler(0, 0, 90f));
firepersec = starttimebtwnshots;
}
}
else
{
firepersec -= Time.deltaTime;
}
}
}
Comment
Answer by frankrs · Feb 06 at 01:24 AM
controls.Gameplay.Shoot.performed += Shoot; controls.Gameplay.Shoot.Enable();
put controls.Gameplay.Shoot.Disable()
in the OnDisable() method also to prevent memory leaks
Your answer
Follow this Question
Related Questions
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
Using Oculus headgear position as input. 0 Answers
Yeild Problems 1 Answer
input system sometimes detects keys 0 Answers