Search Unity

applying Vector 3 to List

Discussion in 'Scripting' started by kalisclark, Nov 26, 2014.

  1. kalisclark

    kalisclark

    Joined:
    Sep 29, 2014
    Posts:
    33
    Hi guys,

    I have a problem which I can't seem to work out.

    I have a list and when I add an item to the list it will create a sphere.

    Simple enough, but how would I then assign a different position for each of those spheres that have been created?

    I attempted to add item and pass 3 float values and then change them to a vector 3 after the sphere was created but it didn't work, all it does is set the position back to default.

    Any advice would be welcome.
     
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    No code shown = no idea what you've done or what needs fixed.
     
  3. kalisclark

    kalisclark

    Joined:
    Sep 29, 2014
    Posts:
    33
    List<Sphere> spheres;

    void Start () {

    spheres= new List<Sphere>();

    SpawnSpheres();
    }

    void SpawnSpheres()
    {
    spheres.Add(new Doorway(25, 45, 1));
    spheres.Add (new Doorway(0,0,0));
    spheres.Add(new Doorway(2, 4, 1));

    foreach(Sphere Madespheres in spheres){

    GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere)
    sphere.transform.localScale = new Vector3(300, 300, 300);

    }

    }

    }

    public class Spheres
    {
    public Spheres (float x, float y, float z)
    {
     
  4. kalisclark

    kalisclark

    Joined:
    Sep 29, 2014
    Posts:
    33
    So as you can see, I am passing the float values but I need to apply them to the individual list items.
     
  5. kalisclark

    kalisclark

    Joined:
    Sep 29, 2014
    Posts:
    33
    Never mind, I realised I didn't need the Foreach loop and just needed to pass the parameters, I was staring at it too long I suppose.