Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.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_Spawning - Fatal编程技术网

C# 统一子弹产卵

C# 统一子弹产卵,c#,unity3d,spawning,C#,Unity3d,Spawning,嗨,由于某些原因,我的子弹不会在我告诉它的地方产卵。 繁殖点在枪管的末端,当我实例化子弹时,我获取它的变换位置和旋转,但它繁殖的高度比枪高(远高于枪)。 以下是我的代码: Animation anim; // Gun animation when shooting AudioSource gunSound; // Gun sound when firing public Rigidbody bullet; // I get the rigidbody of the bullet th

嗨,由于某些原因,我的子弹不会在我告诉它的地方产卵。 繁殖点在枪管的末端,当我实例化子弹时,我获取它的变换位置和旋转,但它繁殖的高度比枪高(远高于枪)。 以下是我的代码:

    Animation anim;   // Gun animation when shooting
AudioSource gunSound; // Gun sound when firing
public Rigidbody bullet; // I get the rigidbody of the bullet that will be spawned
public Transform spawnPoint; // The position of where it is supposed to spawn


void Start()
{
    anim = GetComponent<Animation>();
    gunSound = GetComponent<AudioSource>();
}

void Update()
{
    if (Input.GetButtonDown("Fire1"))  // If the left mouse button is clicked
    {
        Rigidbody bulletInstance;
        bulletInstance = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as Rigidbody; // This is where I don't understand why?!?!
        bulletInstance.AddForce(spawnPoint.forward * 1000f);

        gunSound.Play();
        //anim.Play("GunShot4");
    }
}
动画动画;//射击时的枪动画
音频源枪声;//枪声
公共刚体项目符号;//我得到了将产生的子弹的刚体
公共转换点;//产卵的位置
void Start()
{
anim=GetComponent();
gunSound=GetComponent();
}
无效更新()
{
if(Input.GetButtonDown(“Fire1”)//如果单击鼠标左键
{
刚体实例;
bulletInstance=实例化(bullet,spawnPoint.position,spawnPoint.rotation)为刚体;//这就是我不明白为什么的地方?!?!
bulletInstance.AddForce(spawnPoint.forward*1000f);
枪声;
//动漫游戏(“枪战4”);
}
}

帮助:)

可能会发生,项目符号的原点不在模型的中间。

那么项目符号不会出现在给定变换的位置?是否有任何附加的脚本可以传送它?除了角色控制器脚本,它位于父对象的父对象上,不会影响枪的任何内容,不,什么都没有。是的,它不是出现在spawnpoint(空的游戏对象)变换中,而是产生更高的值,就像在描述顶部链接的图片中一样(第一行)啊,可能是“公共刚体子弹”需要是“公共游戏对象子弹”,你需要将其实例化为“游戏对象”,而不是“作为刚体”。您可以使用gameObject.GetComponent()引用刚体;谢谢,我用一个球体改变了子弹模型,效果很好。。我拖拽并扔掉了我的子弹预制板,但它看起来像是在正确的地方,但它是固定的:)再次感谢!