Ok, I am trying to make a gun shooting and working so it’s working but the bullets fly only in one direction.
Which is driving me insane.
This is the Script that I stick on to the player but the problem I would assume is in the bullet script or bullet spawn so I provided both. Thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
public GameObject bullet;
public GameObject bulletSpawn;
public float fireRate;
private Transform _bullet;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
Fire();
}
public void Fire()
{
_bullet = Instantiate(bullet.transform, bulletSpawn.transform.position, Quaternion.identity);
}
}
And this code goes on to the bullet
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float aliveTime;
public float damage;
public float movSpeed;
public GameObject bulletSpawn;
// Start is called before the first frame update
void Start()
{
bulletSpawn = GameObject.Find("Bullet Spawn");
this.transform.rotation = bulletSpawn.transform.rotation;
}
// Update is called once per frame
void Update()
{
aliveTime -= 1 * Time.deltaTime;
if (aliveTime <= 0)
Destroy(this.gameObject);
this.transform.Translate(Vector3.forward * Time.deltaTime * movSpeed);
}
}