I try to make weapons in unity 2D .one of them is the shotgun, so I need to make bullets spread.I used Quaternion.Euler to solve the problem but doesn't work.There is another problem in Random.Range() when I write r of Random in capital it says there is an error, also when I write it in small another error please help me. this is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
public Transform firePoint;
public GameObject bulletPrefab;
public Weapon currentWeapon;
private float nextTimeOfFire = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Fire1")){
if(currentWeapon){
if(Time.time >= nextTimeOfFire){
for(float x = 0;x < currentWeapon.bullets; x++){
Shoot();
}
nextTimeOfFire = Time.time + 1 / currentWeapon.fireRate;
}
}
}
}
void Shoot(){
Instantiate(bulletPrefab, firePoint.position, Quaternion.Euler(firePoint.rotation.x,firePoint.rotation.y + Random.Range(-currentWeapon.spread, currentWeapon.spread), 0f));
}
}
I'm a beginner in unity and sorry for bad English
Aucun commentaire:
Enregistrer un commentaire