일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- UE5
- 시작해요 언리얼 2022
- python
- Unity
- 오류
- Basic
- 기초
- Tutorial
- c++
- parameter
- Programming
- C#
- W3Schools
- w3school
- loop
- 문제풀이
- 백준
- github
- 파이썬
- Class
- Algorithm
- 프로그래밍
- dfs
- dynamic
- DP
- 재귀
- String
- Material
- Unreal Engine 5
- guide
- Today
- Total
행복한 개구리
Unity 3D 21.04.14.복습 본문
오늘 배웠던 네비게이션, 시네머신등을 이용하여
1.맵안의 주인공은 가만히 있고
2.총을 자동으로 쏘며
3.회전기능을 넣어서
4.몰려오는 적(좀비)을 잡는 디펜스게임을 만들려고 한다.
하지만 학원에서 했을 때 막무가내로 계획없이 구현하려다가 중간에 생기는 스크립트가 많아져 일단 다이어그램을 이용하여 계획을 먼저 짜고 제작을 들어가려고 한다. 개발도 연습해야하지만 이런 설계를 하는 것도 연습을 해둬야 후에 도움이 크게 될 것 같다.
학원에서 대충 정했던 순서는 이러하다.
4.DetectTarget
2.PlayerHp
3.CollisionCheck -> DecreaseHp
1.automatic shooting -> IK, LineRenderer
5.Zombie Hp
ㄴdecreaseZombieHp
ㄴZombieDie
============================================================================

아직은 미숙하지만 그래도 설계해봤다. 하면서 추가되면 다시 업뎃예정.
============================================================================


회전버튼을 만들고 GunPivot 오브젝트를 이용하여 대략적인 총의 위치를 정해주었다.
============================================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
Rigidbody playerRigid;
float rotateCoef = 1;
float rotateSpeed = 90f;
// Start is called before the first frame update
void Start()
{
this.playerRigid = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (GameManager.instance.isRotate)
{
Debug.LogFormat("난 문제없음 :D");
Rotate();
}
}
private void Rotate()
{
float turn = rotateCoef * rotateSpeed * Time.deltaTime;
playerRigid.rotation = playerRigid.rotation * Quaternion.Euler(0, turn, 0);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public UI ui;
public bool isOver = false;
public bool isRotate = false;
public static GameManager instance
{
get
{
if(m_instance == null)
{
m_instance = FindObjectOfType<GameManager>();
}
return m_instance;
}
}
private static GameManager m_instance;
private void Awake()
{
if (instance != this)
{
Destroy(this.gameObject);
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (this.isRotate)
{
Debug.Log(this.isRotate);
}
}
private void GameOver()
{
if (this.isOver)
{
this.ui.GameOverUI.gameObject.SetActive(true);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI : MonoBehaviour
{
public TextAlignment scoreText;
public Button rotateButton;
public GameObject GameOverUI;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class RotationButton : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
EventTrigger eventTriggers = gameObject.GetComponent<EventTrigger>();
EventTrigger.Entry entry_PointerDown = new EventTrigger.Entry();
entry_PointerDown.eventID = EventTriggerType.PointerDown;
entry_PointerDown.callback.AddListener((data) => GameManager.instance.isRotate = true);
eventTriggers.triggers.Add(entry_PointerDown);
EventTrigger.Entry entry_PointerUp = new EventTrigger.Entry();
entry_PointerUp.eventID = EventTriggerType.PointerUp;
entry_PointerUp.callback.AddListener((data) => GameManager.instance.isRotate = false);
eventTriggers.triggers.Add(entry_PointerUp);
}
// Update is called once per frame
void Update()
{
}
}
Rotate버튼을 눌러도 GameManager의 인스턴스가 없다고 그래서 m_instance를 private으로 바꾸고 Awake의 잘못썻던 식을 다시 고쳐쓰니 게임매니저는 해결됐다. 하지만 여전히 안되는걸 봐선 Rotate이벤트쪽 문제인듯 싶다.
'Unity > 복습' 카테고리의 다른 글
Unity 21.04.23. 데이터 불러오기 및 저장 복습 (0) | 2021.04.23 |
---|---|
Unity GUI 21.04.22. 복습 (0) | 2021.04.22 |
Unity GUI 21.04.21.복습 - 데이터 및 인벤토리 슬롯 불러오기 (0) | 2021.04.21 |
Unity 3D 21.04.15.복습 (0) | 2021.04.15 |
Unity 21.04.08.복습 (0) | 2021.04.08 |