Skip to content

Instantly share code, notes, and snippets.

@Naxum
Created May 22, 2014 23:38
Show Gist options
  • Save Naxum/e42f37e15bb503913ec5 to your computer and use it in GitHub Desktop.
Save Naxum/e42f37e15bb503913ec5 to your computer and use it in GitHub Desktop.
How to spawn a gameobject with a component and keep track of it
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ActorManager : MonoBehaviour
{
public Actor actorPrefab;
public List<Actor> actors = new List<Actor>();
void Start()
{
Actor actor = (Instantiate(actorPrefab.gameObject, Vector3.Zero, Quaterion.Identity) as GameObject).GetComponent<Actor>();
//do anything to actor
actors.Add(actor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment