Roll a Ball 게임 Pick Up Objects 수집
PlayerController에 코드를 추가해 줍니다.
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 | using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { public float speed; private Rigidbody rb; void Start() { rb = GetComponent<Rigidbody>(); } void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rb.AddForce(movement * speed); } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Pick Up")) { other.gameObject.SetActive(false); } } } | cs |
Pick Up의 태그를 지정해 줍시다.
정확하게 같은 이름을 사용해야 하므로 복붙을 추천 합니다.
Pick Up을 선택
Is Trigger 체크
게임 실행 할시 상자들이 중력에 의해 바닥을 통과 하면서 떨어진다.
리지드바디를 이용해 다음과 같은 상황을 해결한다.
1. 중력을 없애는 방법
2.Is Kinematic을 사용하는 방법(추천)
물리력에 반응하지 않고 트랜스 폼을 이욯.
이제 상자가 떨어지지 않고 완젹하게 움직입니다.
'프로그래밍 > UNITY' 카테고리의 다른 글
[UNITY]Roll a Ball 게임 Pick Up Objects 게임 배포 (0) | 2018.11.11 |
---|---|
[UNITY]Roll a Ball 게임 Pick Up Objects 마무리 (0) | 2018.11.11 |
[UNITY]Roll a Ball 게임 Pick Up Objects (0) | 2018.11.11 |
[UNITY]Roll a Ball 게임 게임 필드 설정 (0) | 2018.11.11 |
[UNITY]Roll a Ball 게임 카메라 움직이기 (0) | 2018.11.11 |