我如何布尔(禁用/启用)SetActive我的对象

本文关键字:SetActive 我的 对象 启用 何布尔 禁用 | 更新日期: 2023-09-27 18:11:14

我需要布尔SetActive例如,我想setaction为假的对象,然后我想setaction为真,但当我玩我的游戏和第一个SetActive为假的对象(男孩。max)我不能返回我的对象,即使我的set Active将为真

using UnityEngine;
using System.Collections;
public class Hidden : MonoBehaviour {
// Use this for initializatio
// Update is called once per frame
void Update(){
    if(Input.GetButtonDown ("Fire1")){
        gameObject.SetActive(false);
        Debug.Log("Remove");
    }
    if(Input.GetButtonDown ("Fire2")){
        gameObject.SetActive(true);
        Debug.Log("Return");
        }
    }
}

这是我的问题视频:https://drive.google.com/open?id=0B-1NrBmZJDU2LWwyZlloNll4NWs

我如何布尔(禁用/启用)SetActive我的对象

一旦禁用GameObject,其所有组件将停止运行。这包括脚本告诉它再次打开自己。当它根本没有读取任何信息时,它是如何读取信息并重新打开的?因此,您必须从外部禁用它。

using UnityEngine;
using System.Collections;
public class HideObject : MonoBehaviour {
public GameObject objectToHide;
// Update is called once per frame
void Update(){
    if(Input.GetButtonDown ("Fire1")){
        objectToHide.SetActive(false);
        Debug.Log("Remove");
    }
    if(Input.GetButtonDown ("Fire2")){
        objectToHide.SetActive(true);
        Debug.Log("Return");
        }
    }
}