2025년을 위한 프로젝트를 시작했습니다.
이번 목표는 1년으로, 지난 작품에서 미흡했던 부분들을 진행하려고 합니다.
마법사키우기 2탄입니다.
뭔가 화려하지만 엄청 많은 적이 몰려오고 부수는 그런점이 부족했던것 같습니다.
탄막을 좋아하는데, 못보여드린것 같은것 같네요.
오늘이 첫번째 날로서 분위기랑 어울리는 Asset 을 구매 하였습니다.
많이 기대해주세요.
2025년을 위한 프로젝트를 시작했습니다.
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class DownBlock : MonoBehaviour
{
Transform tf = null;
Rigidbody2D rg = null;
public float maxScale = 3.0f;
public bool rightMove = true;
public float moveSpeed = 4.0f;
public bool drop = false;
public bool needCheck = false;
public static string gameState = "playing";
// Start is called before the first frame update
private void Awake()
{
tf = GetComponent<Transform>();
tf.localScale = new Vector3(0f, 0f, 0f);
rg = GetComponent<Rigidbody2D>();
rg.gravityScale = 0f;
drop = false;
needCheck = false;
}
// Update is called once per frame
void Update()
{
if (gameState == "gameend")
{
GetComponent<Rigidbody2D>().gravityScale = 1f;
drop = true;
}
if (tf.localScale.x >= maxScale && drop==false && (Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)))
{
GetComponent<Rigidbody2D>().gravityScale = 1f;
drop = true;
}
}
void FixedUpdate()
{
Vector3 scale = tf.localScale;
bool havetomove = false;
if (!drop)
{
if (scale.x < maxScale)
{
scale.x = scale.x + 8f * Time.fixedDeltaTime;
scale.y = scale.x;
}
else
{
scale.x = maxScale;
scale.y = scale.x;
havetomove = true;
}
tf.localScale = new Vector3(scale.x, scale.y, 0f);
if (havetomove)
{
Vector3 pos = rg.position;
if (rightMove)
{
pos.x = pos.x + moveSpeed * Time.fixedDeltaTime;
}
else
{
pos.x = pos.x - moveSpeed * Time.fixedDeltaTime;
}
rg.MovePosition(new Vector3(pos.x, pos.y, pos.z));
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Wall"))
{
if (rightMove)
{
rightMove = false;
}
else
{
rightMove = true;
}
}
else if (collision.gameObject.CompareTag("DeadWall"))
{
gameState = "gameover";
Destroy(gameObject);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("DontCare"))
{
needCheck = true;
}
}
}
private void Awake()
{
tf = GetComponent<Transform>();
tf.localScale = new Vector3(0f, 0f, 0f);
rg = GetComponent<Rigidbody2D>();
rg.gravityScale = 0f;
drop = false;
needCheck = false;
}
tf.localScale = new Vector3(0f, 0f, 0f);
if (gameState == "gameend")
{
GetComponent<Rigidbody2D>().gravityScale = 1f;
drop = true;
}
if (tf.localScale.x >= maxScale && drop==false && (Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)))
{
GetComponent<Rigidbody2D>().gravityScale = 1f;
drop = true;
}
if (scale.x < maxScale)
{
scale.x = scale.x + 8f * Time.fixedDeltaTime;
scale.y = scale.x;
}
tf.localScale = new Vector3(scale.x, scale.y, 0f);
scale.x = maxScale;
scale.y = scale.x;
havetomove = true;
if (havetomove)
{
Vector3 pos = rg.position;
if (rightMove)
{
pos.x = pos.x + moveSpeed * Time.fixedDeltaTime;
}
else
{
pos.x = pos.x - moveSpeed * Time.fixedDeltaTime;
}
rg.MovePosition(new Vector3(pos.x, pos.y, pos.z));
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Wall"))
{
if (rightMove)
{
rightMove = false;
}
else
{
rightMove = true;
}
}
else if (collision.gameObject.CompareTag("DeadWall"))
{
gameState = "gameover";
Destroy(gameObject);
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("DontCare"))
{
needCheck = true;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public GameObject genObj;
public GameObject startPanel;
public GameObject gameoverPanel;
public GameObject scoreText;
public Transform genPosition;
public float invokeTimer = 1.0f;
int score = 0;
float mainCamTargetY = 0f;
// Start is called before the first frame update
void Start()
{
instance = this;
DownBlock.gameState = "playing";
if (gameoverPanel)
{
gameoverPanel.SetActive(false);
}
if (invokeTimer > 0f)
{
Invoke("InvokeFunction", invokeTimer);
Invoke("InvokeStartImageDeActive", invokeTimer);
}
score = 0;
}
// Update is called once per frame
void Update()
{
if (DownBlock.gameState == "playing")
{
GameObject[] block = GameObject.FindGameObjectsWithTag("Player");
float maxVelocy = -1f;
float maxY = -100f;
int dropFalseCount = 0;
int blockCount = 0;
for (int i = 0; i < block.Length; i++)
{
DownBlock downBlock = block[i].GetComponent<DownBlock>();
Rigidbody2D rd = block[i].GetComponent<Rigidbody2D>();
if (rd != null)
{
if (!downBlock.drop)
{
dropFalseCount++;
continue;
}
else if (!downBlock.needCheck)
{
dropFalseCount++;
continue;
}
else
{
if (maxVelocy < rd.velocity.magnitude)
{
maxVelocy = rd.velocity.magnitude;
}
if (maxY < rd.position.y)
{
maxY = rd.position.y;
}
blockCount++;
}
}
}
GameObject mainCam = GameObject.FindGameObjectWithTag("MainCamera");
if (block.Length > 0 && dropFalseCount == 0 && maxVelocy < 0.1f)
{
{
InvokeFunction();
if (maxY + 2 > mainCam.transform.position.y)
{
mainCamTargetY = maxY + 2;
}
score = blockCount;
}
}
if (mainCamTargetY > mainCam.transform.position.y)
{
mainCam.transform.position = new Vector3(mainCam.transform.position.x, mainCam.transform.position.y + 0.5f * Time.deltaTime, mainCam.transform.position.z);
}
}
else if (DownBlock.gameState == "gameover")
{
if (gameoverPanel)
{
gameoverPanel.SetActive(true);
}
}
if (scoreText)
{
scoreText.GetComponent<Text>().text = score.ToString();
}
}
void InvokeFunction()
{
GameObject result;
result = Instantiate(genObj);
result.transform.position = genPosition.transform.position;
}
void InvokeStartImageDeActive()
{
if (startPanel)
{
startPanel.SetActive(false);
}
}
}
void Start()
{
instance = this;
DownBlock.gameState = "playing";
if (gameoverPanel)
{
gameoverPanel.SetActive(false);
}
if (invokeTimer > 0f)
{
Invoke("InvokeFunction", invokeTimer);
Invoke("InvokeStartImageDeActive", invokeTimer);
}
score = 0;
}
Invoke("InvokeFunction", invokeTimer);
Invoke("InvokeStartImageDeActive", invokeTimer);
void InvokeFunction()
{
GameObject result;
result = Instantiate(genObj);
result.transform.position = genPosition.transform.position;
}
void InvokeStartImageDeActive()
{
if (startPanel)
{
startPanel.SetActive(false);
}
}
GameObject[] block = GameObject.FindGameObjectsWithTag("Player");
float maxVelocy = -1f;
float maxY = -100f;
int dropFalseCount = 0;
int blockCount = 0;
for (int i = 0; i < block.Length; i++)
{
DownBlock downBlock = block[i].GetComponent<DownBlock>();
Rigidbody2D rd = block[i].GetComponent<Rigidbody2D>();
if (rd != null)
{
if (!downBlock.drop)
{
dropFalseCount++;
continue;
}
else if (!downBlock.needCheck)
{
dropFalseCount++;
continue;
}
else
{
if (maxVelocy < rd.velocity.magnitude)
{
maxVelocy = rd.velocity.magnitude;
}
if (maxY < rd.position.y)
{
maxY = rd.position.y;
}
blockCount++;
}
}
}
GameObject mainCam = GameObject.FindGameObjectWithTag("MainCamera");
if (block.Length > 0 && dropFalseCount == 0 && maxVelocy < 0.1f)
{
{
InvokeFunction();
if (maxY + 2 > mainCam.transform.position.y)
{
mainCamTargetY = maxY + 2;
}
score = blockCount;
}
}
if (mainCamTargetY > mainCam.transform.position.y)
{
mainCam.transform.position = new Vector3(mainCam.transform.position.x, mainCam.transform.position.y + 0.5f * Time.deltaTime, mainCam.transform.position.z);
}
mainCam.transform.position = new Vector3(mainCam.transform.position.x, mainCam.transform.position.y + 0.5f * Time.deltaTime, mainCam.transform.position.z);
else if (DownBlock.gameState == "gameover")
{
if (gameoverPanel)
{
gameoverPanel.SetActive(true);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ChangeScene : MonoBehaviour
{
public string sceneName;
public void Load()
{
SceneManager.LoadScene(sceneName);
}
}
if (scoreText)
{
scoreText.GetComponent<Text>().text = score.ToString();
}