[Solved] Unity 3D spawn 10 objects on mouseclick [closed]


To instantiate a prefab you can use Instantiate (as someone told you in a comment) https://docs.unity3d.com/ScriptReference/Object.Instantiate.html

to do that 10 times use a simple for-loop: for(int i=0; i<10; ++i){ //code }

so, putting all togheter the update functions can be:

void Update () 
{
    if (Input.GetMouseButtonDown ("Fire1")) 
    {
        for (int i = 0; i < 10; ++i){
            Instantiate(m_oMyPrefab, m_oMyPosition, m_oMyRotation);
        }
    }
}

Note that m_oMyPrefab must be a GameObject variable with a reference to your prefab (you can do it programmatically or with the inspector editor), m_oMyPosition must be a Vector3 with the desired position and m_oMyRotation must be a Quaternion. Position and rotation are optionals, see the documentation for more details.

1

solved Unity 3D spawn 10 objects on mouseclick [closed]