- Home /
How do I instantiate a textObject prefab?
Below I pasted my current code. While there are no compiler errors, nothing seems to be instantiating. P.S. if anyone knows how write to the console in monodevelop that would be greatly appreciated (Either I’m being dense and can’t see it or Console.Write isn’t accessing anything).
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI;
public class Create_Text : MonoBehaviour {
ArrayList arr = new ArrayList();
// Use this for initialization void Start () { arr.Add ("I am"); arr.Add ("The"); arr.Add ("Best"); Position (arr); }
void Position(ArrayList arr){ foreach (string item in arr) { if (arr.Count > 20) { createCircle (20); } else { createCircle (arr.Count); } }
}
public Text textObject; public Camera camera; public int radius; private ArrayList pos; void createCircle(int num){ textObject = GetComponent (); camera = GetComponent (); Vector3 camPos = camera.transform.position;
for(int i = 0; i< 360; i+= (360/num)){ pos.Add(new Vector3((float)(camPos.x + (radius *Math.Acos(i))), (float)(camPos.y + (radius *Math.Asin(i))), camPos.z)); } setupText (); }
void setupText(){ for (int i = 0; i < pos.Count; i++) { Console.Write ("I'm here"); drawText ((Vector3) pos[i], (String) arr [i]); } }
void drawText(Vector3 v, String text){ textObject = GetComponent(); Instantiate (textObject, v,Camera.main.transform.rotation); }
// Update is called once per frame void Update () {
} }
You need to better format your code. Press the space bar 4 times, and then paste it to your question.