Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9517

[Unity初心者]プレハブからオブジェクトを生成

$
0
0

概要

1:コードを書いて
2:プレハブを登録

本文

publicGameObjectPrefabObject;voidStart(){Vector3pos=newVector3(0,0,0);Instantiate(PrefabObject,pos,Quaternion.identity);//オブジェクト、位置(省略可)、無回転(省略可)//GameObject obj = Instantiate(PrefabObject, pos, Quaternion.identity);}

コードを書いて空のオブジェクトにAddComponentする。

スクリーンショット_(45).png
そこに生成したいキャラ(プレハブ)をドラッグアンドドロップする。

追記

RigidbodyとBox Colliderを有効にしてコードを繰り返し実行するようにするとこんな感じになります(同じ位置に生成してるから)
スクリーンショット (44).png

Quaternionについての動画(すごく難しいから興味のある人だけ)
https://www.youtube.com/watch?v=uKWLPU8gfIY


Viewing all articles
Browse latest Browse all 9517

Trending Articles