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;
}
}
}