[英]How to create custom 3D name using c# script in Unity 3D
I'm stuck on ac# scripting problem in Unity that I would like to solve. 我陷入了要解决的Unity中的ac#脚本问题。
This is what I want to achieve: 这是我要实现的目标:
This is what I have done so far: 到目前为止,这是我所做的:
GUI 图形用户界面
SCRIPT button_scr
脚本button_scr
public class button_scr : MonoBehaviour
{
public Button myButton;
public InputField un;
public GameObject go;
void Start ()
{
myButton = GetComponent<Button>();
myButton.onClick.AddListener(ProcessText);
}
void ProcessText()
{
Debug.Log("Your name is : "+un.text);
getCharacters(un.text);
}
void getCharacters(string text)
{
foreach (char c in text)
{
go = GameObject.Find(""+char.ToUpper(c));
go.SetActive (true);
// setPosicionNext2EachOther
// setColoredMaterial(Blue,Green,Red,Yellow) in this order
Debug.Log("GameObject name Log: "+go.name);
}
}
}
Some considerations: 一些注意事项:
This is where I would like to get some orientation in order to solve the problem: 这是我想要解决问题的方向:
GameObject[0] = A 3D Character prefab
GameObject[1] = B 3D Character prefab
Is there any easier way to do this that I'm missing? 有什么更简单的方法可以实现我所缺少的吗?
I would like to get some orientation/advice or some sample code where I can check similar issue solving. 我想获得一些方向/建议或一些示例代码,在这里我可以检查类似的问题解决方法。
this is a quick solution. 这是一个快速的解决方案。 not tested.
未经测试。 i dont have unity installed.
我没有统一安装。 just for you to have an idea.
只为您有一个主意。
Yes. 是。 is better to assign all the letters in a array for optimization.
最好在数组中分配所有字母以进行优化。 Also deactivate all the letters in Awake()
同时停用Awake()中的所有字母
public Material materials[]; // assign the materials in the order you want
public void getCharacters (string name)
{
int materialIndex = 0;
for (int i = 0; i < text.lenght; i++)
{
char c = char.ToUpper(text[i]);
GameObject go = GameObject.Find("" + c);
go.SetActive (true);
go.transform.position = new Vector3(i, 0, 0); // place the letters in the x axis separated by one meter
// change the material
go.GetCOmponent<Renderer>().sharedMaterial = materials[materialIndex];
materialIndex = (materialIndex + 1) % materials.length; // cycle the materials
// setPosicionNext2EachOther
// setColoredMaterial(Blue,Green,Red,Yellow) in this order
//Debug.Log("GameObject name Log: "+go.name);
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.