Project (43) 썸네일형 리스트형 [전투 시스템] Unity: 적 컨트롤러 만들기 (2) 코루틴을 사용한 적 움직임 구현입니다. 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 43 44 45 46 IEnumerator EnemyControl() { while (true) { float x = transform.position.x + Random.Range(-1f, 1f); float y = transform.position.y + Random.Range(-1f, 1f); Vector2 target = new Vector2(x, y); target = CheckTarget(target); prevPosition = transform... [전투 시스템] Unity: 적 컨트롤러 만들기 (1) 플레이어와는 다르게 적은 입력에 따라 움직임을 적용하지 않고, 시간에 따라서 움직임을 적용합니다. 원하는 패턴이 있다면 그 패턴을 명시해줘야 원하는 방법으로 움직이게 될 것입니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 using System.Collections; using UnityEngine; using UnityEngine.UI; public class EnemyController : CharacterStats { public Transform attackTransform; public Image img; Vector2 prevPosition; Animator animator; Rigidbody2D rigid; SpriteR.. [전투 시스템] 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 43 44 45 46 47 48 49 50 51 using UnityEngine; using UnityEngine.UI; public class PlayerController : CharacterStats { public int jumpPower; public Transform attackTransform; Animator animator; Rigidbody2D rigid; SpriteRenderer sprite; Transform tran.. [전투 시스템] Unity: 부모 스크립트 만들기 먼저 플레이어와 적 오브젝트가 상속받을 부모 스크립트부터 설명하겠습니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 using UnityEngine; public class CharacterStats : MonoBehaviour { [SerializeField] public float health { get; private set; } public float maxHealth = 100; public int attackPower; public float moveSpeed; public float attackRadius; public float attackReload = 2; public float nextAttackTime; 5행의 [SerializeField]를 통해서 상속받은 자식 오.. [전투 시스템] Unity: 게임 구조 아래 은 완성된 게임 구조에 대해서 보여주는 것입니다. [우다다다 고영희] 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.. 이전 1 2 3 4 5 6 다음