Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

@Maru60014236's pickup articles

Maru60014236

@Maru60014236(まる: もっと早く教えてほしかった!Unity C#入門 著者)

UdemyでUnityアプリ開発にまつわる講座を出しております!割引リンクはブログサイトにて公開中🔍https://marumaro7.hatenablog.com/about 自作スマホアプリ数11作 特級機械加工技能士 職業訓練指導員免許所持 普段の業務では教育係を担い、その過程で教え方の勉強をしてきました。その知識を使って、初めての方でもわかりやすい記事を書いていきます。

Comments

No comments

Let's comment your feelings that are more than good

Qiita Conference 2024 Autumn will be held!: 11/14(Thu) - 11/15(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

Takahiro Anno, Masaki Fujimoto, Yukihiro Matsumoto(Matz), Shusaku Uesugi / Nicolas Ishihara(Vercel Inc.)

View event details

Being held Article posting campaign

4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address