3d 프로젝트 생성
안드로이드 빌드 세팅
Models , Sounds 에 챕터8 리소스 넣기
Save as 에서 GameScene저장
1920x1080 Landscape로 화면 조정
stage 끌어오고
언팩하고
Dictional Light 위치 조정
Intensity 0.7
바스켓의 그림자 변경하기
Edit -> Project Settings -> Qullity -> Shadow Distance(150->30) 변경
변경 후 모습
바스켓을 상.하.좌.우로 이동하기
Scriptes 파일을 만들고
스크립트 생성
Basket 오브젝트에 넣어준다
라이트 설정과 코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasketController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 3);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.LogFormat("{0} -> {1}", hit.point.x, Mathf.RoundToInt(hit.point.x));
Debug.LogFormat("{0} -> {1}", hit.point.z, Mathf.RoundToInt(hit.point.z));
}
}
}
}
stage 오브젝트에 Box Collider를 붙인다
사이즈 조정 3, 0.1 ,3
바구니 칸 나눠서 이동하기 코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasketController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 3);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.LogFormat("{0} -> {1}", hit.point.x, Mathf.RoundToInt(hit.point.x));
Debug.LogFormat("{0} -> {1}", hit.point.z, Mathf.RoundToInt(hit.point.z));
float x = Mathf.RoundToInt(hit.point.x);
float z = Mathf.RoundToInt(hit.point.z);
this.transform.position = new Vector3(x, 0, z);
}
}
}
}
사과 드랍하기
위치 -1, 3, 0 으로 해준다
그림자를 보면 사과가 어디로 떨어질지 파악가능함
언팩
폭탄 드랍
위치 1, 3, 0으로 해준다
언팩
사과, 폭탄 지면에 닫으면 파괴
ItemController 스크립트를 만들고 사과, 폭탄 오브젝트에 넣는다
DropSpeed는 사과 2, 폭탄 3 으로 해주었다
사과, 폭탄 파괴 코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemController : MonoBehaviour
{
public float dropSpeed = 2f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
this.transform.Translate(Vector3.down * this.dropSpeed * Time.deltaTime);
if(this.transform.position.y < -1)
{
Destroy(this.gameObject);
}
}
}
'Unity > 수업 내용' 카테고리의 다른 글
[UGUI] StudyUI - slider (0) | 2021.11.03 |
---|---|
[UGUI] StudyUI 준비하기 (0) | 2021.10.28 |
[3D] MiniRPG - 플레이어 버튼 생성 (0) | 2021.10.22 |
[3D] MiniRPG - 플레이어 생성 및 컨트롤 (0) | 2021.10.19 |
[3D] MiniRPG 준비 및 리소스 (0) | 2021.10.19 |