playMaker

Author Topic: Help with Instantiate - RERUN! (sry)  (Read 1978 times)

broesby

  • Playmaker Newbie
  • *
  • Posts: 14
Help with Instantiate - RERUN! (sry)
« on: April 28, 2015, 05:21:33 AM »
Please,... anyone who could help me with at least some of this - I'm really stuck here  :'( - so I post it a second time...

I am making a small galaxy of stars. I use a Space Graphics Toolkit to create one. The toolkit script only spawns sprites, not actual gameobjects. Luckily there is the option to make an editable copy of the script. I then place a "star" = prefab gameobject at each sprite-position. I am using this script to do it:

Code: [Select]
using UnityEngine;
using System.Collections;

public class Star : MonoBehaviour {
public Transform probe;

// Use this for initialization
void Start () {

foreach (var star in GetComponent<SgtCustomStarfield>().Stars) {
Instantiate (probe, star.Position, Quaternion.identity);
}
}

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

}
}

It works like a charm. One star is instantiated at each position... My problem is now that I want them to be individual / discernible in some way. Either I need them to have unique names or I need them to have a unique variable as identifier to be able to call them later. Right now they are all just named Star(Clone), all identical.

I am no coder  >:( I do everything with playmaker and I usually get along but I cannot figure out wher to go now. I tried asking for help in Unity forum. Got some help but I cannot figure out how to get it put together into working code  :(

Would a kind soul help me to either:

- Show me a way to do the above but with unique names or identifier variables for each star - then I can continue from there with playmaker as I usually do (my prefab has Playmaker FSMs and is thereby "born with some functionality")

- Or show me a way to do the above inside Playmaker

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: Help with Instantiate - RERUN! (sry)
« Reply #1 on: April 28, 2015, 05:50:50 AM »
You could try adding them to a hash table and giving them a key which you could pair with another hash table holding matching strings for names etc
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with Instantiate - RERUN! (sry)
« Reply #2 on: April 29, 2015, 02:18:20 AM »
Hi,

 yep, you should use ArrayMaker for this!

https://hutonggames.fogbugz.com/default.asp?W715

You should make a custom action that will get them stars and put them into an ArrayList of Hashtable ( if you want to refer to stars with a string key), and then inside Fsm, you do a loop on them stars that are now stored in ArrayMaker and you can create your objects, as well as saving them as you do inside another hashtable, using the same keys, and so you'll have two hashtables, one with stars and one with the actual GameObjects, and the link between the two with be their keys.

Bye,

 Jean