вот код помогите
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
public GameObject bullet;
public Camera mainCamera;
public Transform spawnBullet;
public float shootForce;
public float spread;
public ParticleSystem muzzleFlash;
AudioSource audioSource;
public AudioClip shootClip;
public void Start()
{
audioSource = GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
Shoot();
audioSource.PlayOneShot(shootClip);
muzzleFlash.Play;
}
public void Shoot()
{
Ray ray = mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hit;
Vector3 targetPoint;
if (Physics.Raycast(ray, out hit))
targetPoint = hit.point;
else
targetPoint = ray.GetPoint(75);
Vector3 dirWithoutSpread = targetPoint - spawnBullet.position;
float x = Random.Range(-spread, spread);
float y = Random.Range(-spread, spread);
Vector3 dirWithSpread = dirWithoutSpread + new Vector3(x, y, 0);
GameObject currentBullet = Instantiate(bullet, spawnBullet.position, Quaternion.identity);
currentBullet.transform.forward = dirWithSpread.normalized;
currentBullet.GetComponent<Rigidbody>().AddForce(dirWithSpread.normalized * shootForce, ForceMode.Impulse);
}
}