void Start () {
//Invoke("A",3);
//InvokeRepeating("A",2,0.5f);
//print("Start调用");
StartCoroutine("A");//携程在 update调用的间隙执行
}
private void Update()
{
if (Input.GetMouseButtonDown(1))
{
StopAllCoroutines();
StopCoroutine(A());
}
}
//private IEnumerator Start() {
// while (true)
// {
// yield return new WaitForSeconds(1);
// print(156);
// }
// }
private IEnumerator A()
{
while (true)
{
yield return new WaitForSeconds(1f);
print(2);
yield return null;//等待一帧
yield return 0;//等待一帧
//yield return new WaitForFixedUpdate();//等待一个固定帧
//yield return new WaitForEndOfFrame();//等待Update执行完
//yield return null;
// if (Input.GetMouseButton(0))
// {
//yield break;
// }
}
}
GameObject
GameObject 继承于 Object
GameObject有三个构造函数 无参 有名字 有名字和组件
属性
GameObject.layer获取物体在哪个层(知道哪个层后可以通过相机指定渲染哪个层,不渲染哪个层)
GameObject.active判断物体是否激活
GameObject.IsStatic判断物体是否是静态
GameObject.Tag获取物体的Tag值
public static GameObject[] FindGameObjectsWithTag(string tag);获取所有属于该Tag值的物体,只能找到激活的物体
public static GameObject FindGameObjectWithTag(string tag);获取最后一个属于该Tag值的物体(一般只用于唯一)
gameObject.scene获取当前场景
GameObject.gameObject获取当前游戏物体
GameObject.Find获取该物体的名字 只能找到激活的物体
gameObject.AddCommpon<Rigdbody>给物体增加钢体组件
gameObject.CompareTag判断该物体的Tag是否是指定值 返回bool类型
GetComponent<Rigidbody>().mass 获取该钢体属性的信息
GetComponentChildren<>().center 获取子物体的属性信息(也包括自己本身) 只会找激活的第一个子物体
GetComponentChildren<>()(true).center 获取子物体的属性信息 找第一个子物体(不管该物体是不是激活)
GetComponentslnParent<T>().center 获取父物体的属性信息(也包括自己本身)
SetActive(); 通过代码控制组件的勾选(激活)