为什么我的Unity C#子弹毫不及格地保持稳定的速度?
敌人的子弹在敌人射击并开始旋转后弯曲(朝着躲避的球员)。所有内容都是实例化的,并且在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下行引起了问题:
传递
null
而不是this.transform
解决了问题The following line was causing the problem:
Passing
null
instead ofthis.transform
solved the problem