Hi,
I’m starting a class with an object attached to it, but don’t find the way to call this class to replicate the object many times. I started creating a List but unity console said I need to Instantiate instead of creating a List.
How can I do this?
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Electrodes : MonoBehaviour {
public string name = "p 11";
public Vector3 myPosition;
public Vector3 textPosition = new Vector3(10,0,0);
public Color myColor = new Color (255,0,0);
public GameObject electrode ;
public TextMesh n_text;
public void init (string inName, Vector3 inVec) {
name = inName;
myPosition = inVec;
//Destroy (electrode);
}
public void Start(){
GameObject head = GameObject.Find ("Epilepsy_Data");
electrode = GameObject.Find ("Electrode");
electrode.GetComponent<Renderer>().material.SetColor ("_Color", myColor);
electrode.GetComponent<Electrodes> ().name = name;
electrode.transform.parent = head.transform;
n_text = new GameObject (electrode.name).AddComponent <TextMesh> () as TextMesh;
n_text.GetComponent<TextMesh> ().text = electrode.name;
//n_text.font = newFont;
n_text.transform.parent = electrode.transform;
//n_text.GetComponent<Renderer> ().material = n_text.font.material;
//n_text.GetComponent<Renderer> ().material.mainTexture = n_text.font.material.mainTexture;
n_text.GetComponent<MeshRenderer> ().castShadows = false;
n_text.GetComponent<MeshRenderer> ().receiveShadows = false;
n_text.GetComponent<Renderer> ().material.renderQueue = 3000;
n_text.transform.localPosition = new Vector3(0.5f,0,0);
n_text.fontSize = 18;
n_text.richText = true;
//n_text.renderer.gameObject.layer = 1;
n_text.anchor = TextAnchor.MiddleLeft;
n_text.fontStyle = FontStyle.Normal;
}
void Update () {
}
}
I am using Legacy Shaders Bumped Specular
– Zitoox