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


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