回答編集履歴
1
補足
test
CHANGED
@@ -21,3 +21,67 @@
|
|
21
21
|
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
ソースを見る感じだと画像を作るメソッドをわけて、配列からランダムにPrefabを選ぶというアプローチでも良さそうです。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```cs
|
32
|
+
|
33
|
+
using System.Collections;
|
34
|
+
|
35
|
+
using System.Collections.Generic;
|
36
|
+
|
37
|
+
using UnityEngine;
|
38
|
+
|
39
|
+
using UnityEngine.SceneManagement;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
public class Test : MonoBehaviour {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
[SerializeField] GameObject[] imagePrefabs;
|
48
|
+
|
49
|
+
private int counter;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
void Update() {
|
54
|
+
|
55
|
+
if (Input.GetMouseButtonDown(0)) {
|
56
|
+
|
57
|
+
var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
58
|
+
|
59
|
+
pos.z = 0; // カメラ位置調整用
|
60
|
+
|
61
|
+
CreateImage(pos);
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
private void CreateImage(Vector3 pos) {
|
70
|
+
|
71
|
+
var _prefab = imagePrefabs[Random.Range(0,imagePrefabs.Length)];
|
72
|
+
|
73
|
+
var newObj = Instantiate(_prefab,pos, _prefab.transform.rotation);
|
74
|
+
|
75
|
+
newObj.GetComponent<SpriteRenderer>().sortingOrder = counter;
|
76
|
+
|
77
|
+
counter++;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```
|