본문 바로가기

728x90

Project/우다다다 고영희

(10)
[우다다다 고영희] Unity: 오브젝트 파괴(완성) 마지막은 오브젝트의 파괴와 게임 점수 증가에 대해 다루겠습니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ObjectBorder : MonoBehaviour { void OnTriggerEnter2D(Collider2D collision) { if(collision.tag == "Car") { GameManager.GM.AddScore(100); collision.gameObject.SetActive(false); } } } OnTriggerEnter2D를 사용하여 만약 트리거에 Car라는 태그를 가진 오브젝트가 ..
[우다다다 고영희] Unity: 게임 매니저 스크립트 이번에는 게임의 전반적인 흐름을 관리해줄 GameManager 스크립트이다. 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 32 33 34 35 36 37 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { public static GameManager GM; public static int totalScore; public Text sc..
[우다다다 고영희] Unity: 자동차 오브젝트 소환하기 오브젝트 풀에서 자동차 오브젝트를 소환하여 사용하는 것에 대해 알아보겠습니다. 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 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ObjectSpawn : MonoBehaviour { public ObjectManager objectManager; public float spawnBetTimeMin; public float spawnBetTimeMax; float spawnTime; float nextSpawnTime; float timeAfterSpawn..
[우다다다 고영희] Unity: 자동차 오브젝트 움직이기 우다다다 고영희에서 사용되는 자동차 오브젝트를 IEnumerator를 통해서 움직이게 해보겠다. 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 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Car : MonoBehaviour { public float moveSpeed; public Vector2 initTarget = new Vector2(20, 0); Rigidbody2D rigid; Vector2 target; void Start() { rigid = GetComponent(); } void OnEna..
[우다다다 고영희] Unity: UI 화면 구성하기 우다다다 고영희의 UI 구성을 봐보겠습니다. 위의 그림과 같이 배경, 발판 그리고 플레이어와 게임 스코어와 플레이어 생명이 UI에 표시됩니다. 위의 그림은 플레이어가 승리 조건에 달성했을 때 나타나는 게임 승리 UI입니다. 2000점이 되면 게임에 승리하게 되고, 해당 UI가 활성화되었을 때 스페이스 바를 누르게 된다면 게임은 다시 시작하게 됩니다. 위의 그림은 플레이어의 생명이 0이 되었을 때 활성화되는 게임 패배 UI 입니다. 플레이어의 승리 UI와 마찬가지로 해당 UI가 활성화되었을 때 스페이스 바를 누르게 되면 게임은 다시 시작하게 됩니다.
[우다다다 고영희] Unity: 오브젝트 풀링을 이용한 무한 장애물 오브젝트 풀링 구현 오브젝트 풀링의 구현에는 많은 방법이 있으니 찾아보고 본인이 사용하기 편한 방법을 사용하면 될 것 같다. 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 32 33 34 35 36 37 38 39 40 41 42 using System.Collections; using System.Collections.Generic; using UnityEngine; public class ObjectManager : MonoBehaviour { public GameObject car1Prefab; public GameObject car2Prefab; public GameObject car3Prefa..
[우다다다 고영희] Unity: 무한 배경 만들기 백그라운드 스크롤링편에서 다루었던 코드를 그대로 가져와서 실행시켰다. 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 32 33 34 35 36 37 38 39 using System.Collections; using System.Collections.Generic; using UnityEngine; public class BackgroundScrolling : MonoBehaviour { public float speed; public Transform[] backgrounds; float leftPosX = 0f; float rightPosX = 0f; float xScreenHalfSize; flo..
[우다다다 고영희] Unity: 플레이어 움직이기 가장 중요한 고영희를 움직이게 해주겠습니다. 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 32 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public int maxSpeed; public int jumpPower; Rigidbody2D rigid; Animator anim; void Start() { rigid = GetComponent(); anim = GetComponent(); void Update() { Move(); Walk()..

728x90