간단하게 공과 바닥 오브젝트 생성하고 각각의 Material을 만들어 줬습니다.
그리고 C# 스크립트를 생성해서 공에게 줬습니다.
소스코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBall : MonoBehaviour
{
Rigidbody rigid; //rigid 컴포넌트 가져오기
void Awake()
{
rigid = GetComponent<Rigidbody>(); //초기화
}
void FixedUpdate()
{
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
Vector3 move = new Vector3(x, 0, z);
rigid.AddForce(move, ForceMode.Impulse);
}
}
결과
'유니티 3D기본(Roll A Ball)' 카테고리의 다른 글
15. 공중에 떠 있는 아이템 만들고 회전시키기 (0) | 2021.10.24 |
---|---|
14. 점프 및 연속 점프 방지 (0) | 2021.10.24 |
12. 게임 인터페이스 만들기 (UGUI) (0) | 2021.10.22 |
11. 물리 충돌 이벤트 (0) | 2021.10.16 |
10. 힘을 이용하여 물체 움직여보기 (velocity, addForce) (0) | 2021.10.14 |