Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 自动射击时,如何更改射击速度?_C#_Unity3d - Fatal编程技术网

C# 自动射击时,如何更改射击速度?

C# 自动射击时,如何更改射击速度?,c#,unity3d,C#,Unity3d,它不停地射击,但看起来像一颗长长的子弹。 例如,如果我想让它不停地射击,但每次只有一颗子弹?或者发射很多子弹,但是子弹之间有一定的距离 在每个项目符号上,我添加了以下销毁脚本: if(automaticFire == true) { anim.Play("SHOOTING"); LaunchProjectile(); } 但这也是一个问题。如果我将销毁延迟设置为0.2,则子弹射程非常短,但如果我将延迟时间设置为5,

它不停地射击,但看起来像一颗长长的子弹。 例如,如果我想让它不停地射击,但每次只有一颗子弹?或者发射很多子弹,但是子弹之间有一定的距离

在每个项目符号上,我添加了以下销毁脚本:

if(automaticFire == true)
        {
            anim.Play("SHOOTING");
            LaunchProjectile();
        }
但这也是一个问题。如果我将销毁延迟设置为0.2,则子弹射程非常短,但如果我将延迟时间设置为5,则子弹射程将更长,但同时会有大量子弹

销毁和自动模式的逻辑是什么?我应该如何在脚本中执行此操作?

您可以尝试以下操作:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletDestruction : MonoBehaviour
{
    // Start is called before the first frame update
    public void Init()
    {
        StartCoroutine(DestroyBullet());
    }

    IEnumerator DestroyBullet()
    {
        yield return new WaitForSeconds(0.2f);

        Destroy(gameObject);
    }
}
float attackRate=100;
浮动计时器=0;
公共无效更新()
{
timer-=Time.deltaTime;
if(自动点火和定时器)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletDestruction : MonoBehaviour
{
    // Start is called before the first frame update
    public void Init()
    {
        StartCoroutine(DestroyBullet());
    }

    IEnumerator DestroyBullet()
    {
        yield return new WaitForSeconds(0.2f);

        Destroy(gameObject);
    }
}
float attackRate = 100;
float timer = 0;

public void Update()
{
    timer -= Time.deltaTime;
    if(automaticFire && timer <=0)
    {
         Shoot();
         timer = 1/ attackRate;
    }
}