1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class CoinSpawn : MonoBehaviour {
6
7     
public GameObject[] coin;
8     
public Transform spawnPoint;
9
10     
private float spawnTime = 10f;
11     
private float spawnNext = 20f;
12
13     
private float maxHeight = 3f;
14     
private float minHeight = -2f;
15
16     
private float timer;
17
18     
void Start () {
19         timer = Time.time;
20     }
21     
22     
void Update () {
23         
float t = Time.time - timer;
24
25         
if (t >= spawnTime) {
26             transform.position =
new Vector3(spawnPoint.position.x, Random.Range(maxHeight, minHeight));
27             Quaternion spawnRotation = Quaternion.identity;
28             
int rand = Random.Range(0, 2);
29             Instantiate(coin[rand], transform.position, transform.rotation);
30             spawnTime = Time.time + spawnNext;
31         }
32     }
33 }


Gõ tìm kiếm nhanh...