小编dru*_*ch 的帖子

Unity霰弹枪制作

所以我对 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)

c# unity-game-engine raycasting

5
推荐指数
2
解决办法
6275
查看次数

标签 统计

c# ×1

raycasting ×1

unity-game-engine ×1