15bb71750b
1. 에셋 전체적인 수정(캐릭터, 총알, 총 등)
2. 회전시 울타리 밖으로 나갈수있던 현상 수정
- 울타리 전체에 콜라이더를 줌
53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class BulletSpawner : MonoBehaviour
|
|
{
|
|
public GameObject prefab;
|
|
|
|
public float bulletSpeed = 8f;
|
|
|
|
Transform target;
|
|
|
|
public Transform firePoint;
|
|
|
|
|
|
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;
|
|
|
|
transform.LookAt(target);
|
|
|
|
if(time >= rate)
|
|
{
|
|
time = 0f;
|
|
|
|
rate = Random.Range(min, max);
|
|
|
|
GameObject obj = Instantiate(prefab, firePoint.transform.position, firePoint.transform.rotation);
|
|
obj.transform.LookAt(target);
|
|
|
|
Bullet bulletScript = obj.GetComponent<Bullet>();
|
|
if (bulletScript != null)
|
|
{
|
|
bulletScript.speed = bulletSpeed;
|
|
}
|
|
}
|
|
}
|
|
}
|