LoginSignup
4
5

More than 3 years have passed since last update.

【Unity】スクリプトからのオブジェクト表示・非表示、見かけ上の表示・非表示

Posted at

環境

Unity 2019.3.7f1

はじめに

今回はオブジェクトにおける
・表示、非表示
・見かけ上の表示、非表示
について書きます。

見かけ上の非表示というのは
実体はあるけど透明になってしまって見えないという意味です。

コード

・オブジェクト表示
GameObject型の変数.SetActive(true);

・オブジェクト非表示
GameObject型の変数.SetActive(false);

・オブジェクトを見かけ上表示
Renderer型の変数.enabled = true;

・オブジェクトを見かけ上非表示
Renderer型の変数.enabled = false;

具体例

・オブジェクト表示

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    [SerializeField] private GameObject a;//GameObject型の変数aを宣言 好きなゲームオブジェクトをアタッチ

    void Start()
    {
        a.SetActive(true);
    }
}

 
・オブジェクト非表示

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    [SerializeField] private GameObject a;//GameObject型の変数aを宣言 好きなゲームオブジェクトをアタッチ

    void Start()
    {
        a.SetActive(false);
    }
}

 
・オブジェクトを見かけ上表示

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    [SerializeField] private Renderer a;//Renderer型の変数aを宣言 好きなゲームオブジェクトをアタッチ

    void Start()
    {
        a.enabled = true;
    }
}

 
・オブジェクトを見かけ上非表示

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    [SerializeField] private Renderer a;//Renderer型の変数aを宣言 好きなゲームオブジェクトをアタッチ

    void Start()
    {
        a.enabled = true;
    }
}

おわりに

これで表示非表示はばっちり。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5