[Game] Dodge
1. 총알피하기 게임 제작 2. 시간별로 단계 설정 3. 시작화면 및 이펙트, 사운드 삽입
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BulletSpawner : MonoBehaviour
|
||||
{
|
||||
public GameObject prefab;
|
||||
|
||||
public float bulletSpeed = 8f;
|
||||
|
||||
Transform target;
|
||||
|
||||
|
||||
public float min = 0.5f;
|
||||
public float max = 3f;
|
||||
|
||||
float rate;
|
||||
float time;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
time = 0f;
|
||||
rate = Random.Range(min, max);
|
||||
|
||||
target = FindFirstObjectByType<PlayerController>().transform;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
|
||||
if(time >= rate)
|
||||
{
|
||||
time = 0f;
|
||||
|
||||
rate = Random.Range(min, max);
|
||||
|
||||
GameObject obj = Instantiate(prefab, transform.position, transform.rotation);
|
||||
obj.transform.LookAt(target);
|
||||
|
||||
Bullet bulletScript = obj.GetComponent<Bullet>();
|
||||
if (bulletScript != null)
|
||||
{
|
||||
bulletScript.speed = bulletSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user