質問編集履歴
1
スクリプトと説明を追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,3 +29,145 @@
|
|
29
29
|
拙い説明になり申し訳ありません。補足説明が必要であればお答えします。
|
30
30
|
|
31
31
|
ご協力頂けると幸いです。よろしくお願いいたします。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
使用しているスクリプトと解説
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
spaceキーが押されると球体オブジェクトの中のカメラが前進し、一定の位置まで達するとカメラが原点まで戻り、同時に球体オブジェクトに貼り付けられている画像がprefabにある画像と置き換わるというものです。
|
40
|
+
|
41
|
+
![イメージ説明](e8c089a50d7bad64acc36c30b1ab7440.gif)
|
42
|
+
|
43
|
+
※球体を真上から見た画像と右下のカメラ視点の画像。
|
44
|
+
|
45
|
+
```C#
|
46
|
+
|
47
|
+
public class mvcam : MonoBehaviour
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
private GameObject ball_start = null;
|
52
|
+
|
53
|
+
private GameObject ball1 = null;
|
54
|
+
|
55
|
+
private GameObject ball2 = null;
|
56
|
+
|
57
|
+
private GameObject ball3 = null;
|
58
|
+
|
59
|
+
private GameObject ball4 = null;
|
60
|
+
|
61
|
+
private int count = 0;
|
62
|
+
|
63
|
+
private int file_namber = 2;
|
64
|
+
|
65
|
+
public GameObject source; //インスタンスの中継役にする変数
|
66
|
+
|
67
|
+
public Vector3 pos = new Vector3(-11, 0, 0);
|
68
|
+
|
69
|
+
GameObject[] views;
|
70
|
+
|
71
|
+
GameObject[] ball;
|
72
|
+
|
73
|
+
void Start()
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
ball_start = GameObject.Find("view_start"); //スタートをprefabのインスタンスにするとバグる
|
78
|
+
|
79
|
+
source = (GameObject)Resources.Load("Prefabs/view_start");
|
80
|
+
|
81
|
+
ball1 = (GameObject)Instantiate(source);
|
82
|
+
|
83
|
+
ball1.SetActive(false); //ここまでをコピーして使う
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
source = (GameObject)Resources.Load("Prefabs/view" + file_namber);
|
88
|
+
|
89
|
+
ball2 = (GameObject)Instantiate(source);
|
90
|
+
|
91
|
+
ball2.SetActive(false);
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
source = (GameObject)Resources.Load("Prefabs/view3");
|
96
|
+
|
97
|
+
ball3 = (GameObject)Instantiate(source);
|
98
|
+
|
99
|
+
ball3.SetActive(false);
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
source = (GameObject)Resources.Load("Prefabs/view3");
|
104
|
+
|
105
|
+
ball3 = (GameObject)Instantiate(source);
|
106
|
+
|
107
|
+
ball3.SetActive(false);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
source = (GameObject)Resources.Load("Prefabs/view4");
|
112
|
+
|
113
|
+
ball4 = (GameObject)Instantiate(source);
|
114
|
+
|
115
|
+
ball4.SetActive(false);
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
views = new GameObject[] { ball1, ball2, ball4, ball4 };
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
void Update()
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
if (Input.GetKeyDown(KeyCode.Space) && pos.z < 300)
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
pos.z += 30;
|
134
|
+
|
135
|
+
transform.position = pos;
|
136
|
+
|
137
|
+
//print(transform.position.z);
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
else if (Input.GetKeyDown(KeyCode.Space) && pos.z >= 300)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
pos.z = 0;
|
146
|
+
|
147
|
+
transform.position = pos;
|
148
|
+
|
149
|
+
print(count);
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
if (count == 0)
|
154
|
+
|
155
|
+
{ //最初だけprefabじゃないからここで消しとく
|
156
|
+
|
157
|
+
ball_start.SetActive(false);
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
views[count].SetActive(false);
|
162
|
+
|
163
|
+
count += 1;
|
164
|
+
|
165
|
+
views[count].SetActive(true);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
```
|