无法在正确的高度上实例化对象

时间:2014-11-23 21:17:04

标签: c# unity3d

我正在使用FSMDeathState来确定当敌人死亡时,它将丢弃一定的buff,这取决于生成的数字,问题是,因为模型有它的支撑,所以buff在地面上实例化,我该怎么改变呢?

这是代码

public void DeathState(){

        if(randomBuff == 1){
        Rigidbody instanced = Instantiate(dropHpBuff, enemyDropPoint.position, enemyDropPoint.rotation) as Rigidbody; 
    }else if(randomBuff == 2){
        Rigidbody instanced = Instantiate(dropAtkBuff, enemyDropPoint.position, enemyDropPoint.rotation) as Rigidbody; 
    }else if(randomBuff == 3){
        Rigidbody instanced = Instantiate(dropDefBuff, enemyDropPoint.position, enemyDropPoint.rotation) as Rigidbody; 
    }
        GameObject.Destroy(gameObject);

}

1 个答案:

答案 0 :(得分:1)

Empty GameObject放在您喜欢的位置,将其命名为DropPoint。您可以在Editor中执行此操作。然后你可以找到它并保留对它的引用。

private Transform dropPoint;   

void Awake()
{
    dropPoint = transform.Find("DropPoint");
}

public void DeathState()
{
    if(randomBuff == 1)
       Instantiate(dropHpBuff, dropPoint.position, dropPoint.rotation); 
}