1
0

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 1 year has passed since last update.

【Unity】初学者は絶対つまずくであろうGameObgect型の不明を解決する

Last updated at Posted at 2022-12-09

はじめに

GameObgectを何となく使っていたが、自分でゲームを作ろうとするとGameObgectの使い所が曖昧だったので深く調べることにしました。
GameObgectとコンポーネントの関係がかなり密接なので、コンポーネントについても触れなから解説していきたいと思います。

GameObgectとは

ゲームオブジェクトは空の箱でる。
ゲームオブジェクトは箱である為、自身では何もしない。動かす為には、その動作をさせるパーツであるコンポーネントが必要。

スクリーンショット 2022-12-09 11.02.53.png

上記の写真のように、 Boardというゲームオブジェクト の中には、Transform と Board(Script) というコンポーネントがある。

TransformとBoardという動きができる素材がBoardという箱の中にあることで、Boardという箱すなわちBoardというゲームオブジェクトを動作させることが出来るのです。

GameObgect型はどのような時に使うのか

一例としての使い型では以下のような使い方がある。

GameObjectを検索(取得)したい時
GameObject.Find("取得したいオブジェクトの名前")

(インスペクタから直接選択可能)ゲームオブジェクトに格納したい時
[SerializeField]
private GameObject 格納したい変数;

タグ名でゲームオブジェクトを取得したい時
GameObject object1 = GameObject.FindGameObjectWithTag("取得したいオブジェクト名前");

スクリプトから消去したい時
Destroy("消去したいオブジェクト名前");

最後に

ゲームオブジェクト型はコンポーネントを敷き詰めた箱のようなものである。
ゲームオブジェクトを取得、消去、格納などをしたい時にゲームオブジェクト型(クラス)を指定した上で指定のオブジェクトを書くことで取得できる。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?