게임 재시작하기
투사체 발사 딜레이 넣기
미사일을 발사하는 함수
private void playerFire()
{
// 제어변수가 true일때만 발동
if (FireState = true)
{
// 인풋 매니저의 "Fire1"에 해당하는 키를 누르면
if (Input.GetButton("Fire1"))
{
// 코루틴 "FireCycleControl"이 실행
StartCoroutine(FireCycleControl());
}
// 코루틴 함수
IEnumerator FireCycleControl()
{
// 처음에 FireState를 false로 만들고
FireState = false;
// FireDelay초(사격딜레이) 후에
yield return new WaitForSeconds(FireDelay);
// 다시 FireState를 true로 만든다.
FireState = true;
}
탄창까지 적용시
void Shoot()
{
if (FireState)
{
if (Input.GetButton("Fire1") && 1 <= magazine)
{
StartCoroutine(FireCycleControl());
// 탄창의 탄알 -1
magazine -= 1;
// 총구 위치
에서 총알복제본 생성
GameObject firePoint = Instantiate(bulletPrefab);
firePoint.transform.position = GetComponent<Transform>().position;
// 재장전 UI 탄 1발 빼기
UI_Mag.GetComponent<Image>().fillAmount -= 0.1f;
// 재장전 필요 여부 체크
ReloadCheck();
}
}
void ManualReload()
{
// 키보드의 'R'키를 누르면
if (Input.GetKeyDown(KeyCode.R))
{
// reloadingTime 후 재장전 함수 실행
Invoke("Reloading", reloadingTime);
}
}
void Reloading()
{
magazine = 10;
// 탄창 UI 초기화
UI_Mag.GetComponent<Image>().fillAmount = 1;
}
카메라 흔들림 효과 넣기
public GameObject cam;
// 카메라 흔들림 중심점을 Vector3.zero(좌표값 중앙 0,0,0)로 설정
public Vector3 cameraPos = Vector3.zero;
void Start()
{
cameraPos = cam.transform.position;
}
public void Shaking()
{
// 코루틴 설정
StartCoroutine(CameraShake(0.5f, 0.5f));
}
// 흔들림 지속시간 및 강도
public IEnumerator CameraShake(float tillTime, float shakeSense)
{
float timeGo = 0;
float posX = 0, posY = 0;
while (timeGo < tillTime)
{
timeGo += Time.deltaTime;
// 랜덤한 X, Y 방향으로 특정 강도로 흔들기
posX = Random.Range(-1 * shakeSense, shakeSense);
posY = Random.Range(-1 * shakeSense, shakeSense);
cam.transform.position = new Vector3(posX, posY, -10);
yield return new WaitForEndOfFrame();
}
cam.transform.position = cameraPos;
}