Hi.
I had a little problem implementing shoot, because I’m working with the Unity Starter Assets - First Person Character Controller, which has the new input system. Fortunately, I found a video of CodeMonkey, where he explains how to shoot using this asset pack and I thought I should share it, so anyone with the same problem would have the solution: Awesome Third Person Shooter Controller! (Unity Tutorial) - YouTube.
In short:
1, In StarterAssets (Input Action Asset) make a new input action for Firing (you can use Jump as an example)
2, Using the example of jump/sprint, add the following lines to StarterAssetsInputs.cs:
public bool fire;
public void OnFire(InputValue value)
{
FireInput(value.isPressed);
}
public void FireInput(bool newFireState)
{
fire = newFireState;
}
3, In Weapon.cs add the following lines:
private StarterAssetsInputs starterAssetsInputs;
void Awake()
{
starterAssetsInputs = FindObjectOfType<StarterAssetsInputs>();
}
4, Lastly, I added the line starterAssetsInputs.fire = false; at the end of my Shoot(); method, this way I will only Shoot once when pressing the left mouse button:
void Shoot()
{
RaycastHit hit;
Physics.Raycast(FPCamera.transform.position, FPCamera.transform.forward, out hit, range);
Debug.Log("I hit" + hit.transform.name);
starterAssetsInputs.fire = false;
}
I hope this will be of some help!