0
public GameObject RIPEnemigo;        

void Rekt()
{
    GameObject RIP = (GameObject)Instantiate(RIPEnemy, transform.position, transform.rotation); //Instantiate of the particles
    Destroy(gameObject); //Destroys enemy
    Destroy(RIP, 2f); //Destroys particles
}

I added the particles prefab and everything in the inspector is OK, but it says:

UnassignedReferenceException: The variable RIPEnemy of Bullet has not been assigned

You probably need to assign the RIPEnemy variable of the Bullet script in the inspector.

RIPEnemy is a particle effect

Why? It's easy, when enemy gets hit -> particles -> RIP Enemy -> RIP Particles. I've searched in the forum but I don't understand where's my error

5
  • What exactly is RIPEnemy? Have you looked in the inspector and ensured you dragged a GameObject onto it? Commented Sep 14, 2016 at 19:59
  • Everything in the inspector is fine, thanks. RIPEnemy is a particle effect Commented Sep 14, 2016 at 20:04
  • 1
    You probably need an assignment before calling Instantiate. Something like RIPEnemy = new ParticleEffect(); (or whatever that type happens to be). Without a stack trace as well as what actual type RIPEnemy is though no one here can answer that for you. Commented Sep 14, 2016 at 20:06
  • public GameObject RIPEnemigo; Commented Sep 14, 2016 at 20:42
  • You uh...you mean RIPEnemy, not RIPEnemigo, right? Otherwise that is a problem. Commented Sep 14, 2016 at 20:48

2 Answers 2

4

Looking at your code I believe that, assuming you assigned RIPEnemigo in the inspector or by code, the line

GameObject RIP = (GameObject)Instantiate(RIPEnemy, transform.position, transform.rotation);

Should be

GameObject RIP = (GameObject)Instantiate(RIPEnemigo, transform.position, transform.rotation);

That should fix your problem.

Sign up to request clarification or add additional context in comments.

Comments

1

Check out the script is not attached to any other game object in the hierarchy and it is not duplicated. The prefab is assigned in one script's instance, but not in the other one

1 Comment

I am new to Unity. I accidentally added script twice and also to more than one object. It worked for me. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.