[Game] Dodge

1. 총알피하기 게임 제작
2. 시간별로 단계 설정
3. 시작화면 및 이펙트, 사운드 삽입
This commit is contained in:
jongjae0305
2026-04-14 17:06:58 +09:00
parent fecfdfad48
commit 2e4370481b
1544 changed files with 1227782 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float speed = 8f;
private Rigidbody rb;
public GameObject effect;
public AudioSource audio;
public AudioClip clip;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Shield"))
{
return;
}
if (other.CompareTag("Player"))
{
Instantiate(effect, other.transform.position, Quaternion.identity);
PlayerController pc = other.GetComponent<PlayerController>();
if (pc != null)
{
pc.Die();
GameObject.Find("Music").GetComponent<AudioSource>().Stop();
}
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
rb = GetComponent<Rigidbody>();
rb.linearVelocity = transform.forward * speed;
Destroy(gameObject, 3f);
}
// Update is called once per frame
void Update()
{
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8742fd0daf5c7a34eb1c615552cca52e
+48
View File
@@ -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;
}
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d24b6e1f590a3664ea844a54866cc26b
+61
View File
@@ -0,0 +1,61 @@
using NUnit.Framework.Constraints;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject gameoverText;
public Text timeText;
public Text recordText;
private float surviveTime;
private bool isGameover;
public void EndGame()
{
isGameover = true;
gameoverText.SetActive(true);
float bestTime = PlayerPrefs.GetFloat("BestTime");
if(surviveTime > bestTime)
{
bestTime = surviveTime;
PlayerPrefs.SetFloat("BestTime", bestTime);
}
recordText.text = "Best Time: " + (int)bestTime;
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
surviveTime = 0;
isGameover = false;
}
// Update is called once per frame
void Update()
{
if(!isGameover)
{
surviveTime += Time.deltaTime;
timeText.text = "Time: " + (int)surviveTime;
}
else
{
if(Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene("Game");
}
}
}
public float GetSurviveTime()
{
return surviveTime;
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7e4ba2ede7843784fae74f235a66f368
+89
View File
@@ -0,0 +1,89 @@
using UnityEngine;
public class NewMonoBehaviourScript : MonoBehaviour
{
public GameObject[] spawners;
public Rotator rotator;
private GameManager gameManager;
private int currentStep = 0;
void Start()
{
gameManager = FindFirstObjectByType<GameManager>();
InitializeDifficulty();
}
void Update()
{
if (gameManager == null) return;
float currentTime = gameManager.GetSurviveTime();
int targetStep = 1;
if (currentTime > 30f) targetStep = 4;
else if (currentTime > 20f) targetStep = 3;
else if (currentTime > 10f) targetStep = 2;
else targetStep = 1;
if (currentStep != targetStep)
{
UpdateStep(targetStep);
}
}
void InitializeDifficulty()
{
foreach (var s in spawners) s.SetActive(false);
if (rotator != null) rotator.enabled = false;
UpdateStep(1);
}
void UpdateStep(int step)
{
currentStep = step;
switch (step)
{
case 1 :
SetSpawnersActive(2);
if (rotator != null) rotator.enabled = false;
break;
case 2 :
SetSpawnersActive(4);
break;
case 3 :
SetSpawnersActive(4);
if (rotator != null) rotator.enabled = true;
break;
case 4:
SetSpawnersActive(4);
if (rotator != null) rotator.enabled = true;
UpgradeBullSpeed(12f);
break;
}
}
void SetSpawnersActive(int count)
{
for(int i = 0; i < spawners.Length; i++)
{
spawners[i].SetActive(i < count);
}
}
void UpgradeBullSpeed(float newSpeed)
{
foreach (var obj in spawners)
{
if (obj == null) continue;
BulletSpawner spawner = obj.GetComponent<BulletSpawner>();
if (spawner != null) spawner.bulletSpeed = newSpeed;
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2ff2d5d670d73194188e933827e87ceb
+87
View File
@@ -0,0 +1,87 @@
using TMPro;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; //코드로 ui를 건들기 위해서 임포트
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRigidbody;
public float speed = 8f;
public int shieldCount = 3; //초기 실드 수
private bool isShieldActive = false; //실드 발동여부
public GameObject shieldVisual; //하이라이어키 실드
public Image shieldIcon; // 실드 이미지 아이콘
public TextMeshProUGUI countText; //글자
public void Die()
{
gameObject.SetActive(false);
GameManager gm = FindFirstObjectByType<GameManager>();
gm.EndGame();
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
playerRigidbody = GetComponent<Rigidbody>();
UpdateShieldUI(); //함수발동
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
float xSpeed = x * speed;
float zSpeed = z * speed;
Vector3 newVelocity = new Vector3(xSpeed, 0f, zSpeed);
playerRigidbody.linearVelocity = newVelocity;
if (Input.GetKeyDown(KeyCode.Alpha1) && shieldCount > 0 && !isShieldActive) //1숫자가 눌리고 카운트가 1이상이고 실드가 활동한 상태이면
{
StartCoroutine(ActivateShield()); //비동기적으로 함수를 발동하라
}
}
void UpdateShieldUI()
{
if (countText != null) //텍스트가 비어있지 않다면
{
countText.text = shieldCount.ToString(); //실드의 카운트를 문자열로 저장
if (shieldCount <= 0)
{
countText.gameObject.SetActive(false); //0이하면 활동에 페일즈를 저장
if (shieldIcon != null)
{
shieldIcon.color = new Color(0.2f, 0.2f, 0.2f, 0.5f);
}
}
}
}
IEnumerator ActivateShield() //코루틴
{
isShieldActive = true; //실드는 트루로 변경
shieldCount--; //실드 카운트는 감소
UpdateShieldUI(); //업데이트
if (shieldVisual != null) shieldVisual.SetActive(true); //만약에 실드비주얼이 비어있지 않다면 트루를 저장
yield return new WaitForSeconds(2f); // 2초동안만
if (shieldVisual != null) shieldVisual.SetActive(false); //만약에 실드비주얼이 비어있지 않다면면 페일즈
isShieldActive = false; //실드 페일즈
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b32f0aba899d4c3419e21f8471a75657
+12
View File
@@ -0,0 +1,12 @@
using UnityEngine;
public class Rotator : MonoBehaviour
{
public float speed = 60f;
void Update()
{
transform.Rotate(0f, speed*Time.deltaTime, 0f);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 69ff7931b6ff8924ba03035fafcc4f0a
+22
View File
@@ -0,0 +1,22 @@
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneChange : MonoBehaviour
{
public void Change()
{
SceneManager.LoadScene("Game");
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8605eef595b0bc24083f9b91604e354d
+12
View File
@@ -0,0 +1,12 @@
using UnityEngine;
public class Shield : MonoBehaviour
{ private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Bullet"))
{
Destroy(other.gameObject);
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b8b34afd2b2a4654db4c96d0556032ab