facebook twitter hatena line email

「Unity/3d/基本」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(アタッチオブジェクトのcanvasの位置)
(ポリゴン数)
 
(同じ利用者による、間の7版が非表示)
行9: 行9:
 
# cubeを選択し、Inspectorの最下のAddComponentからPhysics/Rigidbodyを選択
 
# cubeを選択し、Inspectorの最下のAddComponentからPhysics/Rigidbodyを選択
 
# cubeの衝突のComponent(Colinder)はもともとついてるので何もしなくて良い。
 
# cubeの衝突のComponent(Colinder)はもともとついてるので何もしなくて良い。
 
==Prefabで複製を作成する==
 
例としてcubeを複製
 
# Hieraruchyに3Dオブジェクト/cubeを選択し追加
 
# Project(Assetsの下に)にResourcesディレクトリを作成する
 
# cubeをResourcesディレクトリへドラッグする
 
以下コードで複製できる
 
for (int i = 0; i < 100; i++) {
 
            float x = Random.Range(-5.0f, 5.0f);
 
            float y = i  * 2 - 4f;
 
            float z = Random.Range(-5.0f, 5.0f);
 
            GameObject prefab = (GameObject)Resources.Load("Sphere");
 
            Vector3 position = new Vector3(x, y, z);
 
            GameObject obj = Instantiate(prefab, position, Quaternion.identity);
 
            obj.name = "sphere" + i;
 
}
 
 
Resourcesディレクトリはオブジェクトを読込時に使われるディレクトリ名でunityのルールらしい。
 
 
==Prefabで複製したものを削除==
 
List<GameObject> list_obj = new List<GameObject>();
 
for (int i = 0; i < 100; i++) {
 
            float x = Random.Range(-5.0f, 5.0f);
 
            float y = i  * 2 - 4f;
 
            float z = Random.Range(-5.0f, 5.0f);
 
            GameObject prefab = (GameObject)Resources.Load("Sphere");
 
            Vector3 position = new Vector3(x, y, z);
 
            GameObject obj = Instantiate(prefab, position, Quaternion.identity);
 
}
 
list_obj.Add(obj);
 
 
// 削除チェック
 
for (int i = 0; i < list_obj.Count; i++)
 
{
 
            GameObject obj = list_obj[i];
 
            if (obj == null) {
 
                continue;
 
            }
 
            if (obj.transform.position.y < -10) {
 
                Destroy(list_obj[i]);
 
                Debug.Log("削除 i=" + i);
 
            }
 
}
 
==アタッチオブジェクトのcanvasの位置==
 
SetParentを使う
 
<pre>
 
GameObject rObject;
 
GameObject rouletteImage;
 
GameObject prefab = (GameObject)Resources.Load("RObject");
 
Vector3 position = new Vector3(
 
            rouletteBackImage.transform.localPosition.x,
 
            rouletteBackImage.transform.localPosition.y,
 
            rouletteBackImage.transform.localPosition.z - 0.2f);
 
GameObject rObject = Instantiate(prefab, position, Quaternion.identity);
 
rObject.name = "RObject" + angle;
 
rObject.transform.SetParent(rouletteImage.transform);
 
rObject.transform.localScale = new Vector3(152.68f, 152.68f, 152.68f);
 
rObject.transform.localPosition = new Vector3(0f, 0f, - 30f);
 
</pre>
 
SetParentとlocalScaleなどの順番によって表示が異なるので気をつける。基本的にはSetParentを先に追加がわかりやすいと思う。
 
 
 
もしくはInstantiateの第4パラメータを使う。
 
  GameObject obj = Instantiate(prefab, position, Quaternion.identity, rouletteBackImage.transform);
 
  
 
==床==
 
==床==
 
3D/Planeを作ればよい。
 
3D/Planeを作ればよい。
 +
 +
==オブジェクトの種類==
 +
*Cube 立方体
 +
*Sphere 球
 +
*Capsule 縦長の球
 +
*Cylinder 柱
 +
*Plane 平面(床とか)
 +
*Quad 平面(ディスプレイとか)
 +
*TextMeshPro テキスト
 +
*Ragdoll 人形(重力によりそのまま倒れる)
 +
*Terain 地形
 +
*Tree 木
 +
*WindZone 風
 +
3DText 旧テキスト

2022年8月23日 (火) 23:00時点における最新版

3D_Helloworld

  1. 新規プロジェクトで3Dを選択
  2. Hieraruchyで3Dオブジェクト/cubeを選択
  3. cubeを(0, 0, 0)を選択

重力&衝突追加

  1. 地面となる板を追加するために3Dオブジェクト/Planeを追加
  2. 3Dオブジェクト/cubeを選択し追加
  3. cubeを選択し、Inspectorの最下のAddComponentからPhysics/Rigidbodyを選択
  4. cubeの衝突のComponent(Colinder)はもともとついてるので何もしなくて良い。

3D/Planeを作ればよい。

オブジェクトの種類

  • Cube 立方体
  • Sphere 球
  • Capsule 縦長の球
  • Cylinder 柱
  • Plane 平面(床とか)
  • Quad 平面(ディスプレイとか)
  • TextMeshPro テキスト
  • Ragdoll 人形(重力によりそのまま倒れる)
  • Terain 地形
  • Tree 木
  • WindZone 風

3DText 旧テキスト