Unity3D пытается уничтожить созданный снаряд

Попытка уничтожить снаряды в этом фрагменте кода не работает. Любые предложения приветствуются.

            Rigidbody InstantiateedProjectileLeft = Instantiate(cannonAmmo, firingPointLeft.transform.position, firingPointLeft.transform.rotation) as Rigidbody;
            if (InstantiateedProjectileLeft != null)
            {
                //print ("Firing projectile");
                InstantiateedProjectileLeft.transform.Translate(Vector3.forward);
                InstantiateedProjectileLeft.rigidbody.AddForce(transform.forward * cannonAmmoSpeed);
                //print (InstantiateedProjectileLeft.transform.position.y);
                print ("Destroying left projectile");
                //InstantiateedProjectileLeft.renderer.material.color = Color.clear;

                Destroy(InstantiateedProjectileLeft, 1.0f); // Doesn't work
            }

            Rigidbody InstantiateedProjectileRight = Instantiate(cannonAmmo, firingPointRight.transform.position, firingPointRight.transform.rotation) as Rigidbody;
            if (InstantiateedProjectileRight != null)
            {
                //print ("Firing projectile");
                InstantiateedProjectileRight.transform.Translate(Vector3.forward);
                InstantiateedProjectileRight.rigidbody.AddForce(transform.forward * cannonAmmoSpeed);

                Destroy(InstantiateedProjectileRight, 1.0f); // Doesn't work
            }

person jadkins4    schedule 14.11.2014    source источник
comment
Попробуйте Destroy(InstantiatedProjectileLeft.gameObject, ...)   -  person luqui    schedule 15.11.2014
comment
Спасибо. геймобъект работает.   -  person jadkins4    schedule 15.11.2014


Ответы (1)


Вам нужно вызвать Destroy для GameObject:

Destroy(InstantiatedProjectileLeft.gameObject);
person stromdotcom    schedule 14.11.2014
comment
Большое тебе спасибо. Это сработало. Я посмотрел Destroy и не увидел часть gameObject. Все еще изучаю. - person jadkins4; 15.11.2014