Unity 로드(6): 사전 설정 및 강체

4007 단어 unity

프리셋


정의: 프리셋은 기존 게임 대상의 복제체입니다.
만들기: 게임 대상을 Asset 창으로 드래그하면 만들 수 있습니다. 폴더 Assets에 여러 군데가 있습니다.prefab 파일.
불러오기: 두 가지 방법이 있는데 하나는 편집기에서 미리 설정체를 직접 끌어당겨 장면으로 끌어당기는 것이다.이 경우 코드를 사용하여 동적으로 로드합니다.
GameObject objPrefab = (MonoBehaviour.Instantiate(fab, Vector3.zero, Quaternion.identity) as GameObject);
GameObject objPrefab = (GameObject)Resources.Load("Prefabs/fabname");

전자fab는MonoBehaviour의 공공 구성원 변수로 Resources/Prefabs/myPrefab를 드래그하여 값을 부여한다.후자fabname은 Resources/Prefabs에서 미리 만들어진 파일 이름입니다.
인스턴스화: Instantiate 방법을 사용하여 다음과 같은 재로드가 있는 새 게임 객체를 만들 수 있습니다.
public static Object Instantiate(Object original);
public static Object Instantiate(Object original, Transform parent);
public static Object Instantiate(Object original, Transform parent, bool worldPositionStays);
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent);

강체


편집기에서 게임 객체에 구성 요소인 Rigidbody를 추가하면 다음과 같은 방법을 사용할 수 있습니다.
Rigidbody rb = GetComponent();
다음은 편집기에서 조정할 수 있는 옵션을 제공하고 괄호에는 구성 요소의 구성원 변수가 있습니다.
Mass(mass) 질량, 몇 단위 Dray(dray)의 직선 운동을 나타내는 공기 저항 Angular Dray(angularDray) 각저항 Use Gravity(use Gravity)가 중력 Is Kinematic(isKinematic)가 동력학을 사용하는지 여부를 나타내며, Use Gravity와 함께 Interpolate 삽입값 Collision Detection 충돌 탐지 방식인 Constraints가 어느 방향의 직선이나 회전 운동을 금지하는 것을 선택할 수 없습니다.
using UnityEngine;
using System.Collections;

public class Cube : MonoBehaviour {

    public Rigidbody rb;

    void Start () {
        rb = GetComponent();
    }

    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown(KeyCode.Alpha1)) {
            //   -> Y 
            // rb.AddForce(new Vector3(0f, 10f, 0f));

            //   -> Y 
            // rb.AddTorque(new Vector3(0f, 10f, 0f));

            //  
            // rb.AddForceAtPosition(new Vector3(0f, 10f, 0f),new Vector3(0.5f, 0.5f, 0.5f));

            //  
            // rb.AddExplosionForce(100f, Vector3.zero, 4f);
        }
    }
}

충돌체 크기는 편집기에서 조정할 수 있습니다.Unity는 기본적으로 다양한 형태의 충돌 구성 요소를 제공합니다. 그 중에서 격자 팽창기는 사용자 정의 격자를 사용하여 충돌 모양을 지정할 수 있습니다.
충돌 사건
void On Collision Enter(Collision other) {} 충돌 시작void On Collision Stay(Collision other) {} 충돌 지속void On Collision Exit(Collision other) {} 충돌 종료void On Trigger Enter(Collider other) {} 트리거 범위에 들어갈 때void On Trigger Stay(Collider other) {} 트리거 범위에 있을 때void On Trigger Exit(Collider other) 를 호출합니다.

좋은 웹페이지 즐겨찾기