Search Unity

Not sure why an error occure when an object IS assigned.

Discussion in 'Scripting' started by scr33ner, Dec 29, 2015.

  1. scr33ner

    scr33ner

    Joined:
    May 15, 2012
    Posts:
    188


    What I've got is an object that the player can destroy which deactivates itself & enemies in that area.

    It's strange getting an error once the object is deactivated since the particleFX being used self destructs. In theory, everything is cleaned up.

    I can't figure out why this is happening when the particle is assigned in the inspector.

    Here's the code used:
    Code (CSharp):
    1.         if (other.gameObject.CompareTag ("fireBall"))
    2.         {
    3.             ///deactivates parent spawner at zero
    4.             if (nmeSpawnerHP > 1)
    5.             {
    6.                 AudioSource.PlayClipAtPoint(sfxHitBaseCamp, transform.position, sfxVolume);
    7.                 nmeSpawnerHP = nmeSpawnerHP - fireBallDamage;
    8.                 Instantiate(hitPrtclFX,transform.position,transform.rotation);
    9.             }
    10.             else
    11.             {
    12.                 AudioSource.PlayClipAtPoint(sfxBaseCampXplode, transform.position, sfxVolume);
    13.                 Instantiate(smokeFX,transform.position,transform.rotation);
    14.                 nmeSpawner.SetActive(false);
    15.                 playerBlock.SetActive(false);
    16.                 Instantiate(nmeSpawnerRubble,transform.position,transform.rotation);
    17.             }
    18.         }
    Ideas are welcome.

    Thank you...
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Does it stay assigned when you hit play? Any chance it points to a scene object, rather than a project prefab? AnDoes turning off the autodestruction clear the error?
     
  3. scr33ner

    scr33ner

    Joined:
    May 15, 2012
    Posts:
    188
    Yeah, it stays assigned- I see the particles when it gets hit. It does point to a prefab & not a scene object.

    I need it to Autodestruct otherwise it'll keep on firing- though just for test purposes, I turned it off & the same problem.