public GameObject cubePrefab;
GameObject cloneObj;
void Start () {
Debug.Log(Time.time);
//先输出,在输出
Invoke("CloneCubeObj", 1f);
Invoke("Function2", 2f);
//参数:方法名,第一次调用时间,重复调用的时间间隔频率
InvokeRepeating("CloneCubeObj", 2f, 1f);
}
void Update () {
if (Input.GetKeyDown(KeyCode.A))
{//一般先判断是否在调用,如果在调用先取消调用
if (IsInvoking("CloneCubeObj"))
{
CancelInvoke("CloneCubeObj");
}
}
}
void CloneCubeObj()
{ //Debug.Log("Function2");
Debug.Log(Time.time);
cloneObj = Instantiate(cubePrefab, new Vector3(Random.Range(-3.0f, 3.0f), Random.Range(-2f, 2.0f), 3f),
cubePrefab.transform.rotation) as GameObject;
}
void Function2()
{
Debug.Log("Function2");
Debug.Log(Time.time);
if (cloneObj != null)
{
cloneObj.transform.GetComponent<BoxCollider>().enabled = false;
}
}
GameObject cloneObj;
void Start () {
Debug.Log(Time.time);
//先输出,在输出
Invoke("CloneCubeObj", 1f);
Invoke("Function2", 2f);
//参数:方法名,第一次调用时间,重复调用的时间间隔频率
InvokeRepeating("CloneCubeObj", 2f, 1f);
}
void Update () {
if (Input.GetKeyDown(KeyCode.A))
{//一般先判断是否在调用,如果在调用先取消调用
if (IsInvoking("CloneCubeObj"))
{
CancelInvoke("CloneCubeObj");
}
}
}
void CloneCubeObj()
{ //Debug.Log("Function2");
Debug.Log(Time.time);
cloneObj = Instantiate(cubePrefab, new Vector3(Random.Range(-3.0f, 3.0f), Random.Range(-2f, 2.0f), 3f),
cubePrefab.transform.rotation) as GameObject;
}
void Function2()
{
Debug.Log("Function2");
Debug.Log(Time.time);
if (cloneObj != null)
{
cloneObj.transform.GetComponent<BoxCollider>().enabled = false;
}
}