Instantiating two objects instead of just one? (C#)

Project is attached. Basically my program is set up so that when the ball enters the trigger area, it dies and respawns on top of the paddle (The game is a brick breaker / Break Out clone if that makes what I said less confusing). The problem is, when it respawns two are spawning instead of just one. It’s kinda weird. Hopefully if you look through my project you can see for yourself.

I know this is a ridiculously simple game and concept, but everybody has to start somewhere and this is my first game ever. Help a guy out :slight_smile:

Edit: See 2nd post of mine in this thread for code links

I would recommend putting the code inside of the forum to make it easier for people to look at it and figure out what is wrong. Having to open up a file, look through the project, and figure out where the problem is more work than most are going to do to help out. You are the one who wants the help so make it easier for us to help you and you will get better results. I’ll open it and see what I can find, but just an FYI for next time.

Edit: Never mind I can’t open the .rar file.

Okay here’s the code for each script of mine then. I’ll pastebin them so it’s organized.

Script for Ball: BallScript.cs - Pastebin.com

Script for Brick (Which ball can hit against, part of the game Not sure if needed so I can get help, but posting it anyway): BrickScript.cs - Pastebin.com

Script for Paddle (which ball hits against, also ball spawns on top of this and moves with it until released via spacebar): PaddleScript.cs - Pastebin.com

And finally, the script for the Deathfield (which I believe may be where the issue lies): DeathfieldScript.cs - Pastebin.com

Okay thanks, first thing if your code isn’t going to use anything in Update(), remove it because it will update it even if there is nothing inside of it. Just a quick tip, as far as your problem goes the issue is that you are creating PaddleScript paddleScript in BallScript. Since you are creating this it is calling the start function and the Spawn function giving you that double creation. You can either do it so it doesn’t call Spawn since you already got the paddle object you could just call spawn like this.

public void Die() {
                Destroy( gameObject );
                GameObject paddleObject = GameObject.Find("paddle");
                paddleObject.GetComponent<PaddleScript>().Spawn();
        }

When you do…

PaddleScript paddleScript; // this is creating a new object, also calling the start function

Hope that works for you.

OKAY LOL. I found my issue. I had attached the Deathfield script to my Deathfield prefab twice. SILLY ME.