Search Unity

instantiating a prefab particle system

Discussion in 'Scripting' started by Simpso, Jul 28, 2015.

  1. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    HI Everyone,

    I am getting an error from a script i have written where a particle system will spawn to simulate an object exploding.

    The particles are set to instantiate when the main object is collided with. Here is the code.

    Code (csharp):
    1.  
    2. void OnCollisionEnter2D(Collision2D other)
    3.      {  
    4.      if (other.gameObject.name  == "Player") {
    5.        brick_boom.Play ();
    6.        Instantiate (brick_pop,transform.position,transform.rotation );
    7.         daBrick.enabled = false;
    8.        Destroy (gameObject,2f);
    9.  
    10.      }
    11.      }
    However when i hit the object i get the error Unassigned reference exception.

    I have the public ref set as brick pop and have dragged the brick explosion prefab into that slot in the inspector.

    Any ideas what i am doing wrong?

    Thanks
     
  2. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    Can you tell in which Line the Error Occurs?
    Atm i can't tell what "brick_boom", "daBrick" is,
    maybe there is an error ? Any further Informations ?
     
    Last edited: Jul 28, 2015
  3. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    My mistake. I had two copies of the script attached to the object. Script one didn't have the prefab attached, Causing the error

    Thanks for your looking though.