-3

I want to spawn 4 game objects in my chosen positions when a Button is clicked.Unity 2D C#

Aleks19
  • 47
  • 2
  • 8
  • 1
    What point are you at currently? Do you have a button which calls a function yet? If so, then get references to the prefabs you want to spawn in, call [Instantiate](https://docs.unity3d.com/ScriptReference/Object.Instantiate.html) on each of them and spawn them in at specified [Vector2](https://docs.unity3d.com/ScriptReference/Vector2.html) locations – AidanH Jul 30 '18 at 09:37
  • 2
    Can you add some code and show us what you've tried so far? – Shogunivar Jul 30 '18 at 09:44
  • 1
    Instantiate(yourPrefabObject, yourTranformPossition); – Ivan Kaloyanov Jul 30 '18 at 13:28

1 Answers1

1

Edit: Apparently I didn't understand your question right. if your button object uses a collider. you can detect mouse events on that object. assign this script to your object that has collider.

public Transform prefabToCreate;
public Vector2 posToCreate = Vector2.zero;

void OnMouseDown() {
    Instantiate(prefabToCreate, posToCreate, Quaternion.identity);
}

It's easy to figure out how to make the object 4 times.

p.s: you should explain your question in more detail.

Amin
  • 543
  • 7
  • 12