实例化一个对象并使其向外旋转?

问题描述

我正在尝试制作的一款小游戏中出现“子弹死亡行为”。基本上,我希望它使原始的项目符号删除自身,以指定数量的新项目符号生成一个圆圈。我得到了那部分,但是,我正在努力地给他们适当的轮换。我希望子弹以某种方式旋转,使其背离圆心。这样,当他们移动时,它们会大幅度扩展。这就是我所拥有的:

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

[CreateAssetMenu(menuName = "Weapon/Ranged Weapon/Projectile/Behavior/Death/Explosion")]
public class ExplosionBehavior : ProjectileDeathBehavior
{
    public GameObject projectilePrefab;
    public GameObject explosionEffect;

    public float damage;
    public float projectileSpeed;

    public int projectilesCreated;
    public float radius;
    public LayerMask wall;
    public override void Death(Projectile projectile,Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Projectile") == false)
        {
            if (explosionEffect != null)
            {
                GameObject explosion = Instantiate(explosionEffect,projectile.transform.position,Quaternion.identity);
                Destroy(explosion);
            }

            for (int i = 0; i < projectilesCreated; i++)
            {
                float currentAngle = (2 * Mathf.PI / projectilesCreated) * i;
                float x = Mathf.Cos(currentAngle);
                float y = Mathf.Sin(currentAngle);

                Vector2 position = new Vector2(projectile.transform.position.x + (radius * x),projectile.transform.position.y + (radius * y));

                Quaternion shotRot = Quaternion.Euler(new Vector3(0,currentAngle * Mathf.Rad2Deg)); //This is the part that I am confused on

                GameObject explosionProjectile = Instantiate(projectilePrefab,position,shotRot);
                Projectile projectileScript = explosionProjectile.GetComponent<Projectile>();
                projectileScript.damage = damage;
                projectileScript.projectileSpeed = projectileSpeed;
                Debug.Log("Created");

            }
            Destroy(projectile.gameObject);
        }
    }
}

目前,这有点奏效;大约一半的子弹沿着正确的方向前进。任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)