-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspone.cs
More file actions
40 lines (34 loc) · 1.56 KB
/
spone.cs
File metadata and controls
40 lines (34 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using UnityEngine;
public class GameManager : MonoBehaviour
{
public GameObject[] Prefabs; // 生成するプレファブの配列
private float time; // タイマー用の変数
private int number; // ランダムに選ばれたプレファブのインデックス
//スタートと終わりの目印
public Transform startMarker;
public Transform endMarker;
// スピード
public float speed = 1.0F;
//二点間の距離を入れる
private float distance_two;
void Start()
{
//二点間の距離を代入(スピード調整に使う)
distance_two = Vector3.Distance(startMarker.position, endMarker.position);
time = 1.0f; // Startが呼ばれた時、タイマーを1秒に設定
Vector3 start = transform.position;
Vector3 target = new Vector3(10, -5, 0);
}
void Update()
{
time -= Time.deltaTime; // タイマーを減少させる
if (time <= 0.0f) // タイマーが0以下になったら
{
time = 1.0f; // タイマーをリセット
number = Random.Range(0, Prefabs.Length); // プレファブ配列からランダムにインデックスを選ぶ
Instantiate(Prefabs[number], new Vector3(0, 0, 0), Quaternion.identity); // 選ばれたプレファブを生成
}
float present_Location = (Time.time * speed) / distance_two;
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, present_Location); // timerの変化分だけ移動させる(1秒で目的地)
}
}