C# 激活孩子几秒钟后摧毁游戏对象
这是我的密码C# 激活孩子几秒钟后摧毁游戏对象,c#,unity3d,C#,Unity3d,这是我的密码 void Update () { if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) { if ( Physics.Raycast(ray, out hit, 1000f ) ) { for(int i=0; i< hit.collider.transform.childCount;
void Update ()
{
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began)
{
if ( Physics.Raycast(ray, out hit, 1000f ) )
{
for(int i=0; i< hit.collider.transform.childCount; i++)
{
var child = hit.collider.transform.GetChild(i).gameObject;
if(child != null)
child.SetActive(true);
}
hit.collider.gameObject.GetComponent<SpriteRenderer>().enabled = false;
//Debug.Log(hit.transform.gameObject.name);
}
}
}
void更新()
{
if(Input.touchCount>0&&Input.GetTouch(0.phase==TouchPhase.Start)
{
if(物理射线投射(射线,命中率,1000f))
{
for(int i=0;i
此代码位于场景中的摄影机上。它的作用是允许我触摸游戏对象并进行破坏。我接触的第一个对象是2D精灵,我已经关闭了它的精灵渲染器,并打开了它的子对象,精灵渲染器
然而,我需要一种方法来摧毁游戏对象一旦这样做。我真的不知道如何才能做到这一点 破坏(游戏对象,5)代码>将在5秒内销毁
您还可以在OnMouseDown()中使用,并在更新中保留所有for循环和raycast内容
如果您确实想要OnMouseDown(),您当然需要对象预置上的脚本,而不是摄像头。如果您希望gameobject实现IDisposable接口,请使用Dispose方法您是否只想销毁父游戏对象而不销毁其子游戏?在这种情况下,如果将GO渲染器设置为false,则如下所示
hit.collider.gameObject.renderer.enabled=false代码>必须有效。所以这不是这个问题的答案?那么这个不应该在这里;)