为什么我的Unity C#子弹毫不及格地保持稳定的速度?

发布于 2025-01-21 14:09:17 字数 1110 浏览 3 评论 0原文

敌人的子弹在敌人射击并开始旋转后弯曲(朝着躲避的球员)。所有内容都是实例化的,并且在Update()中调用了攻击,但是CopyofCurrentRotation(我知道在我的代码中拼写错误)仍在更改子弹的速度。

public IEnumerator Attack(string goname)
    {
        IsAttacking = true; //Indicates if we are attacking
        oldmovementspeed = MovementSpd;
        MovementSpd = 0;

        GameObject p = GuitarShooter.GrabObject();
        p.transform.position = exitPoints[0].position;
        p.transform.SetParent(this.transform);
        yield return new WaitForSeconds(2.00f); 
        EvilProjectile q = p.GetComponent<EvilProjectile>();
         q.Initialize(q.MyDamage);

        if (q != null && q.HasBeenFired != true )
        {   
    
            currentRoration = transform.rotation * Vector3.up;
            copyofcurrentRoration = new Vector3(currentRoration.x, currentRoration.y, currentRoration.z);
            q.MyEvilBody.velocity =  CopyOfCurrentRoration * q.MySpeed;
            q.HasBeenFired = true;
           
   
        IsAttacking = false;
    
        MovementSpd = oldmovementspeed;
        StartCoroutine(Reload("morebullets"));
    }

Enemy bullets are curving after the enemy shoots and starts to rotate (towards the player who is dodging). Everything is Instantiated and Attack is called in the Update() however the CopyofCurrentRotation (misspelled in my code, I know) still is changing the velocity of the bullet.

public IEnumerator Attack(string goname)
    {
        IsAttacking = true; //Indicates if we are attacking
        oldmovementspeed = MovementSpd;
        MovementSpd = 0;

        GameObject p = GuitarShooter.GrabObject();
        p.transform.position = exitPoints[0].position;
        p.transform.SetParent(this.transform);
        yield return new WaitForSeconds(2.00f); 
        EvilProjectile q = p.GetComponent<EvilProjectile>();
         q.Initialize(q.MyDamage);

        if (q != null && q.HasBeenFired != true )
        {   
    
            currentRoration = transform.rotation * Vector3.up;
            copyofcurrentRoration = new Vector3(currentRoration.x, currentRoration.y, currentRoration.z);
            q.MyEvilBody.velocity =  CopyOfCurrentRoration * q.MySpeed;
            q.HasBeenFired = true;
           
   
        IsAttacking = false;
    
        MovementSpd = oldmovementspeed;
        StartCoroutine(Reload("morebullets"));
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2025-01-28 14:09:17

以下行引起了问题:

p.transform.SetParent(this.transform);

传递null而不是this.transform解决了问题

p.transform.SetParent(null);

The following line was causing the problem:

p.transform.SetParent(this.transform);

Passing null instead of this.transform solved the problem

p.transform.SetParent(null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文