facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==3D_Helloworld== #新規プロジェクトで3Dを選択 #Hieraruchyで3Dオブジェクト/cubeを選択 #cubeを(0, 0, 0)を選択 ==重力&衝突追加== # 地面...」)
 
(ポリゴン数)
 
(同じ利用者による、間の8版が非表示)
行10: 行10:
 
# cubeの衝突のComponent(Colinder)はもともとついてるので何もしなくて良い。
 
# cubeの衝突のComponent(Colinder)はもともとついてるので何もしなくて良い。
  
==Prefabで複製を作成する==
+
====
例としてcubeを複製
+
3D/Planeを作ればよい。
# 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のルールらしい。
+
==オブジェクトの種類==
 
+
*Cube 立方体
==Prefabで複製したものを削除==
+
*Sphere
List<GameObject> list_obj = new List<GameObject>();
+
*Capsule 縦長の球
for (int i = 0; i < 100; i++) {
+
*Cylinder 柱
            float x = Random.Range(-5.0f, 5.0f);
+
*Plane 平面(床とか)
            float y = i  * 2 - 4f;
+
*Quad 平面(ディスプレイとか)
            float z = Random.Range(-5.0f, 5.0f);
+
*TextMeshPro テキスト
            GameObject prefab = (GameObject)Resources.Load("Sphere");
+
*Ragdoll 人形(重力によりそのまま倒れる)
            Vector3 position = new Vector3(x, y, z);
+
*Terain 地形
            GameObject obj = Instantiate(prefab, position, Quaternion.identity);
+
*Tree 木
}
+
*WindZone 風
list_obj.Add(obj);
+
3DText 旧テキスト
 
+
// 削除チェック
+
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);
+

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 旧テキスト