Instantiate prefab in each vertex (C#)

I am struggling with this for a while now and wondering if anyone can point me in the right direction.

Trying to instantiate a prefab in each vert of a mesh with C#.
When I call the “Instantiate” function it doesn’t recognise the “vertices” variable as it seems to conflict between “Vector3[ ]” and “Vector3” …which totally puzzles me.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Instantiator : MonoBehaviour {

    public GameObject dot;


    // Use this for initialization
    void Start () {

    }


    // Update is called once per frame
    void Update() {

        Mesh mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = mesh.vertices;
        int i = 0;
        while (i < vertices.Length)
        {
            vertices[i] += Vector3.up * Time.deltaTime;
            i++;
        }
        mesh.vertices = vertices;
        mesh.RecalculateBounds();

        Instantiate(dot, vertices, transform.rotation);

    }

}

Thank you

Instantiate creates one of an object at a given position, giving it an array of verticies wont make it spawn at all the points, you have to do it manually.

for(int vertId = 0; vertId < verticies.Length; vertId++;)
{
Instantiate(dot, verticies[vertId], transform.rotation);
}
2 Likes

Ah, got it, it works.
THANK YOU!