Unity中如何给游戏物体通过代码添加组件

Unity中如何给游戏物体通过代码添加组件,第1张

gameObject.AddComponent<YourComponent>()

或者

gameObject.AddComponent("YourComponent")

如何用 代码 控制 text 文本

-------------------------------------------------------------------------------代码

using System.Collections

using System.Collections.Generic

using UnityEngine

using UnityEngine.UI//使用 该引用,才能获得 Text 组件

public class test : MonoBehaviour {

public GameObject GO

public GUIText guit

// Use this for initialization

void Start () {

GO.GetComponent<Text>().text = "6666"

}

}

用cube的IsTrigger。 拖一个cube到场景中,勾掉mesh,collider中勾上IsTrigger,调整collider的大小,在脚本代码中分别实现OnTriggerEnter呃OnTriggerExit函数,在OnTriggerEnter中播放anim,在OnTriggerExit中停止anim,


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11846207.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存