728x90
1. 점수판 만들기
UI -> Canvas 추가 -> Wold Space ->메인카메라 드래그&드롭 -> 메인카메라 하위에 위치 ->Scale 조정
2. 카메라 시야각 잡기
줌인 줌아웃 했을 때 변화, 왜곡
Field of View 45설정
3. Canvas -> Create Empty -> 이름 바꾸기 3DUIRoot
Ham 추가
4. 점수판 만들기
UI ->Text 추가 -> 이름 바꾸기 ItemCount
Canvas에 Dynamic Pixels per Unit 값 10
5. 그림자 없애기
Ham Cast Shadows, Receive Shadows 끄기
디렉션라이트 -> Culling Mask -> UI 뺴기
햄 Layer UI 설정
Ham에 포인트라이트 추가
6. 점수 계산
Create Empty -> Game Manager -> size 4
Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
// 유니티에서 텍스트 참조 빼먹지 마시고연결하고 실행하세요 ^^
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static bool IsGameStop = false;
public Animator backgroundAnimator;
public static int ItemCount = 0;
public Text itemCountText;
public float endDelayTime;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (GameManager.IsGameStop)
{
backgroundAnimator.speed = 0;
}
itemCountText.text = ItemCount.ToString();
}
}
7. 컴포넌트 참조
스프라이트에 있는 ItemPickUp에서 아이템 참조하려고 할 때
아이템 컴포넌트에 있는 것만 참조 가능함
GameManager에 스크립트 붙이고 점수 입력
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemPickup : MonoBehaviour
{
public GameManager gameManager;
//3D 충돌 이벤트 메소드(Collider 컴포넌트의 isTrigger = true 일때)
private void OnTriggerEnter(Collider itemCollider)
{
if (itemCollider.tag == "Item")
{
HamItemState itemState = itemCollider.GetComponent<HamItemState>();
if (itemState != null)
{
gameManager.ScoreUp(itemState.itemType);
}
Debug.Log("아이템을 획득함");
Destroy(itemCollider.gameObject);
}
}
}
'Unity' 카테고리의 다른 글
[유니티] 회전하기 (0) | 2021.05.14 |
---|---|
[유니티] 3D 캐릭터 이동하기 (0) | 2021.05.13 |
[유니티] 효과 넣기 (0) | 2021.05.06 |
[유니티] 지정위치에 랜덤 오브젝트 놓기 (0) | 2021.04.24 |
[유니티] 3D 큐브 생성 + 회전하기 (0) | 2021.04.21 |
댓글