728x90
반응형

유니티 45

AA(14) - 폭탄아이템 횟수 표시&회전

public GameObject[] grenades; public int hasGrenade; 빈 오브젝트를 만들어 4방향으로 폭탄 프리팹을 배치해줍니다. 파티클 컴포넌트도 추가해줍니다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Orbit : MonoBehaviour { public Transform target; public float orbitSpeed; Vector3 offset; void Start() { } void Update() { transform.RotateAround(target.position, Vector3.up, orbitSpeed * Time.deltaTim..

AA(13) - 소모아이템 획득

public int ammo; public int coin; public int health; public int hasGrenade; public int maxAmmo; public int maxCoin; public int maxHealth; public int maxHasGrenade; 소비 아이템들과 그 최댓값의 변수 선언부터 해줍니다. 기본값과 최대값을 설정해줍니다. void OnTriggerEnter(Collider other) { if(other.tag == "Item") { Item item = other.GetComponent(); switch (item.type) { case Item.Type.Ammo: ammo += item.value; if (ammo > maxAmmo) ammo =..

AA(12) - 아이템 제작&착용&교체

원거리 무기 2종, 근거리 무기 1종, 폭탄 오브젝트에 파티클을 붙여서 프리팹으로 저장해줍니다. 프리팹에서 포지션 값은 초기화해줍니다. 체력, 골드 프리팹을 제작합니다. 캐릭터가 주변의 아이템을 감지합니다. 무기 줍기 키를 설정해줍니다. Has Weapons에 획득한 무기가 표기됩니다. 아이템 착용시 적용될 위치에 오브젝트를 붙입니다. 3종류 무기 좌표값을 어색하지 않게 수정해줍니다. 착용 시 활성화를 위해 Weapons에 지정해줍니다. 무기 교체 키를 설정합니다. 획득한 무기만 꺼내고 교체할 수 있도록 스크립트를 수정합니다.

AA(11) - 회피 구현

bool isDodge; void Update() { Dodge(); } void Dodge() { if (jDown && moveVec != Vector3.zero && !isJump && !isDodge) { speed *= 2; anim.SetTrigger("doDodge"); isDodge = true; Invoke("DodgeOut", 0.4f); } } void DodgeOut() { speed *= 0.5f; isDodge = false; } 회피를 위한 스크립트를 추가합니다. 회피 중 방향이 전환되는 걸 막기 위해 dodgeVec을 선언하고 Move()에 조건을 걸어 회피 중 방향이 고정되게 합니다. using System.Collections; using System.Collections..

AA(10) - 점프 구현

bool jDown; Rigidbody rigid; void Awake() { rigid = GetComponent(); } void Update() { Jump(); } void Jump() { if (jDown) { rigid.AddForce(Vector3.up * 5, ForceMode.Impulse); //15만큼 위로 힘을 가함 } } 플레이어 스크립트에 점프를 추가합니다. Floor 태그를 추가해 바닥에 적용해줍니다. bool isJump; void Jump() { if (jDown && !isJump) { rigid.AddForce(Vector3.up * 5, ForceMode.Impulse); //15만큼 위로 힘을 가함 isJump = true; } } void OnCollisionEnt..

AA(9) - 맵&캐릭터 변경, 플레이어 이동

배경은 에셋스토어에서 받은 데모 씬으로 구성합니다. 캐릭터는 Mixamo에서 제공하는 캐릭터를 사용합니다. 데모 신을 메인 씬으로 변경하고 캐릭터에 idle애니메이션을 적용하여 배치합니다. 캐릭터에 리지드바디와 캡슐 콜라이더 컴포넌트를 추가하고 이동을 위해 플레이어 스크립트를 추가합니다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public float speed; float hAxis; float vAxis; Vector3 moveVec; void Start() { } void Update() { hAxis = Input.GetAxisRa..

AA(8) - 드랍 무기 입수&착용

GameObject nearObject; void OnTriggerStay(Collider other) { if (other.tag == "Weapon") nearObject = other.gameObject; Debug.Log(nearObject.name); } void OnTriggerExit(Collider other) { if (other.tag == "Weapon") nearObject = null; } } 무기 태그를 지닌 오브젝트를 감지하도록 스크립트를 추가합니다. 이제부턴 스크립트 전문이 너무 긴 관계로 추가되는 내용만 기록합니다. 콘솔창을 통해 정상적으로 감지되고 있음을 확인할 수 있습니다. public class Player : MonoBehaviour { bool iDown; void..

AA(7) - 캐릭터 변경하기

지금까지 한 내용을 복기하고 다른 프로젝트에서도 사용할 수 있도록 다른 모델링을 구해서 지금까지 내용을 적용해보았습니다. https://assetstore.unity.com/packages/3d/characters/humanoids/humans/asobi-chan-free-116360 Asobi-chan free | 캐릭터 | Unity Asset Store Get the Asobi-chan free package from Asobiya and speed up your game development process. Find this & other 캐릭터 options on the Unity Asset Store. assetstore.unity.com 모델링은 해당 주소의 에셋스토어에서 제공하는 3D 무료..

AA(5) - 아이템 만들기

준비된 프리펩에서 망치를 꺼내 줍니다. 로테이션을 조정해줍니다. 새 자식 오브젝트를 만들고 라이트 컴포넌트를 추가해줍니다. 빛의 세기와 범위, 색을 조정해줍니다. 다시 새로운 자식 오브젝트를 만들고 파티클 시스템 컴포넌트를 추가합니다. 파티클 설정을 조절해줍니다. 망치 오브젝트에 리지드바디와 콜라이더 컴포넌트를 추가해줍니다. 물리 접촉으로 캐릭터 획득을 위한 콜라이더와, 바닥을 뚫고 들어가지 않기 위한 콜라이더 두 개가 필요하기에 스피어콜라이더를 두 개 추가해줍니다. 획득을 위한 콜라이더는 범위를 넓히고 isTrigger를 활성화합니다. Item 스크립트를 새로 생성하고 해머에 추가해줍니다. using System.Collections; using System.Collections.Generic; usi..

유니런 체력 표시하기

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { // 싱글턴 => 공유하는 변수 public static GameManager instance; // 스코어 관리, 게임오버 관리 => 플레이어 사망 // 재시작 관리 => 마우스 클릭 => 재시작 [SerializeField] GameObject gameover; [SerializeField] Text scoreText; public Text hpText; public int hp = 3..

728x90
반응형