所以我对 C# 的随机数学有点陌生,我学会了如何制作步枪、手枪等。但我想学习如何使用光线投射而不是射弹制作霰弹枪。对于光线投射,我厌倦了做超过 1 次光线投射,但不知道如何使它们随机,所以现在我只能使用 1 次光线投射。我想在拍摄时进行随机传播。这是脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotGun : MonoBehaviour {
private int pellets = 9;
private float spreadAngle = 10f;
private float damage = 10f;
private float range = 1000f;
private Camera fpsCam;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown("Fire1"))
{
ShotgunRay();
}
}
private void ShotgunRay()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, …Run Code Online (Sandbox Code Playgroud)