#Ranged weapon
1 messages Β· Page 1 of 1 (latest)
ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
π π π π π π π π π π π π π π
Ok, and what triggers the Shoot action
What do you mean?
What has to happen to trigger the Shoot action and make the gun or whatever it is shoot bullets
There has to be some kind of trigger, it won't just shoot by itself.
I made a command when you press the left mouse button, the Shoot action is captured and activates the bullet shot, it works but the range not
Where is the code for such actions
Show it
using System.Collections;
using UnityEngine;
using StarterAssets;
public class Gun : MonoBehaviour
{
private StarterAssetsInputs _input;
[SerializeField] private GameObject bulletPrefab;
[SerializeField] private GameObject bulletPoint;
[SerializeField] private float bulletSpeed = 600;
void Start()
{
_input = transform.root.GetComponent<StarterAssetsInputs>();
}
// Update is called once per frame
void Update()
{
if (_input.shoot)
{
Shoot();
_input.shoot = false;
}
}
void Shoot()
{
Debug.Log("shoot!");
GameObject bullet = Instantiate(bulletPrefab, bulletPoint.transform.position, transform.rotation);
bullet.GetComponent<Rigidbody>().AddForce(transform.forward * bulletSpeed);
Destroy(bullet, 1);
}
}```
That's all the code
Ok, can't really help since it's the new Input System, haven't been using it at all 
Either wait for some help, call someone from #π±οΈβinput-system or be a heretic and use the old Input System
no problem
thanks
Old input system best