Ниже приведен мой текущий сценарий для стрельбы из пистолета.
Код: Выделить всё
private void Shoot()
{
_audio.Stop();
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().AddForce(dirWithSpread.normalized * shootForce, ForceMode.Impulse);
_audio.time = 0.15f;
_audio.Play();
}
Как лучше всего сделать так, чтобы на стене/поле появилось пулевое отверстие?
п>
Подробнее здесь: https://stackoverflow.com/questions/791 ... a-physical