I cannot spawn new objects in Unity 2D

Lionmeow

Alright, so I've been building a small thing in Unity 2D, and it works for the most part, however whenever I attempt to create a script to spawn a copy of the circle prefab, it just doesn't spawn without any error messages.

I've attempted to use Instantiate to spawn them at the button's location, yet no luck.

{
    public GameObject circle;
    public Transform circlespawn;
    private bool touched = false;

    void Update()
    {
        if(touched == true)
        {
            Instantiate(circle, circlespawn.position, circlespawn.rotation);
            touched = false;
        }
    }

    void OnMouseDown()
    {
        touched = true;
    }
}
Lionmeow

From BugFinder in the comments, he pointed out I simply needed a collider for the onmousedown to work correctly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spawn objects in unity

Unity2D: Spawn objects using array and deleting spawn object once exit out of camera view

Unity 3D, how to spawn objects, and modify their values?

Unity 3D spawn 10 objects on mouseclick

Destroy and Spawn(Respawn) Objects in Unity 3D

PowerShell: Cannot spawn a new thread

All objects in unity project became pink. How can I gix that (unity 2d)

Unity 2D spawn variables won't update

How to spawn random 2D platforms that do not overlap in Unity?

Spawn objects by timer or something else. c# unity 3D

How do I sort array objects and manipulate them to return a new 2D array?

How can I spawn an object on the opposite side of mesh(wall) I'm clicking on in unity3d?

How do I spawn objects on higher ground?

Unity network manager does not spawn objects on network start position

Make objects spawn correctly within different screen widths sizes unity

Unity IDropHandler with 2D objects in 3D space

Unity 2D Help - Random Spawining Of Asteroids Without Having Them Spawn In Camera View

2d Array of objects is not creating new objects, just overwriting

Unity - Instantiated objects spawn on the same position in Coroutine, while instantiate them directly do spawn correctly

unity 2 object spawn on button click

How can I spawn objects in a given volume/area 3d

App get crash on animation of 2d objects in Unity 4.3

Unity 2D change objects position relatively to a Transform

Display 2D objects over others (Unity)

How to change an objects properties by touching it on mobile (UNITY) (2D)

How to avoid object references for spawned objects in Unity 2D?

Am I using Unity or Unity 2D?

Cannot add my scoretext to script in gamecontrol in unity 2d

How Can I Not Make Points Spawn In The Same Place Twice? (Unity)