유니티 3D 1강

3D 김천일 선생님

페이스북 연동
PHP 연동 우편함.
게임서버 - 소캣통신
모바일 빌드.

http://180.70.94.180/fps.html
강사님 사이트


3D는 기본적으로 라이트 의 영향을 받는다.

# 안쓰는 컴포넌트나 소스코드는 반드시 지운다.
# 파티클의 최신버전(방식)은 슈리켄이다.
# 스크립트 자동완성 안될때 ->  프로젝터 창의  showinexploer하여
생성된 파일들 지운다.

9 월 1일 유니티 수업 소스 ( 스크립트 포함)
http://freebox.myqnapcloud.com:8080/share.cgi?ssid=0NaMxVS



 설정에서 2D 3D 바꿀때

 매쉬 랜더러는 애니메이션이 없는...

 마우스 우측키 -> 1점시점으로 회전

 외부 모델링(맥스,마야,시포디) import시 중요한 부분은 크기다.
 유니티는 기본단위가 미터 단위이다.
 
트랜스폼의 1은 1미터(단위)
Directional Light -> 조명.
sky box는 기본적으로 설정 되어 있음



카메라의 기본 위치 값



 그리드의 기본 크기는 1m (1 rectangle)


 

  와이어 프레임으로 보기
 
  texture 입히기.
  
  1. 메터리얼 생성
  2. project로 이미지 불러오기
  3. 


 shader 란?
 그래픽 카드에서 처리하는 작업은 쉐이더 라는 언어로 작용된다
 그래픽스는 GPU 에서 처리한다 GPU는 그래픽 카드에 들어가 있는 CPU

  

  모바일 전용 메터리얼 처리  
  디뷰즈는 가장 기본적인(원래색상 그대로의) 메터리얼 속성.

  
  텍스쳐 타일링 할때




















  매터리얼 선택 -> 타일링값 지정
  타일이 이상할때
  텍스쳐 선택 후 Wrap Mode에서 Repeat로 선택.

 *상속관계를 볼때에는 상속된 스크립트 위에 마우스올려놓고 f12키를 누른다. 
 * 들여쓰기 선택한뒤  쉬프트 탭 : 왼쪽으로, 탭 : 오른쪽으로
 
  
  입력키 설정



  3D 에서의 카메라 이동-   
  01. 회전
===[MouseLook  메인 카메라에 적용]=======================================
  
using UnityEngine;
using System.Collections;
 
public class MouseLook : MonoBehaviour 
{
 
    public float _speed = 100;
 
    float rotationX = 0;
    float rotationY = 0;
    
    void Update () 
    {    
       // 이동공식
       //dir * speed * time
       //방향 * 속도 * 시간 
       // 마우스의 X이동값을 입력받음
       // 방향은 -1 ~ 1 사이에서 사용
       float dirX = Input.GetAxis("Mouse X");
       float dirY = Input.GetAxis("Mouse Y");
 
       // 마우스의 회전값을 가지고 있는 변수
       // X축은 그대로 두고 있어야 하기 때문에 dirY을 대입
       rotationX += dirY * _speed * Time.deltaTime;
       rotationY += dirX * _speed * Time.deltaTime;
 
       // 마우스의 움직임에 따라 이동하는 회전각을 고정
       if (rotationX > 90) rotationX = 90;
       if (rotationX < -90) rotationX = -90;
 
       //회전값을 사용하면 반드시 eulerAngles (오일러앵글스) 를 사용한다.
       transform.eulerAngles = new Vector3(-rotationX, rotationY, 0);
    } }

----------------------------------------------------------------------


 02. 이동 
 플레이어 게임 오브젝트에 컴포넌트 연결
 
 캐릭터 콘트롤러 
 slope limit :
 경사 45이상 못 올라감
  
   

  


































===[PlayerMove 플레이어 오브젝트에 연결]=======================================


using UnityEngine;
using System.Collections;

public class PlayerMove : MonoBehaviour {
 
    public float speed = 5;
    
    // 초기화 주소값을 가진다 = null;
    CharacterController chraCtr = null;
    
    void Start () 
    {
        //chraCtr은 GetComponent의 CharacterController을 참조한다.
        // CharacterController 타입을 찾아서 넘겨준다.
        chraCtr = GetComponent<CharacterController>();
    }
    
    
    void Update () 
    {
        // 캐릭터 컨트롤러의 Move() 메서드를 실행
        // dir * speed * time
        float dirX = Input.GetAxis("Horizontal");
        float dirY = Input.GetAxis("Vertical");
        // 뎁스로 이동해야 하기때문에 z값에 Vertical키의 값을 입력 해준다.
        // Vector3는 3가지 값을 가지기 때문에 앞뒤 전후 좌우 값을 입력 해 줄 수 있다.
        Vector3 dir = new Vector3(dirX, 0, dirY); //dirX 좌우값  dirY 앞뒤값
        
        //180도 돌았을때의 문제 해결
        // 메인카메라 main은 스태틱 언제든지 불러 올 수 있음. 스태틱 변수는 new 가 안됨
        //카메라 게임오브젝트를 기준으로 방향을 설정한다(왼쪽이냐 오른쪽이냐 판별함)
        //dir변수에 카메라 디렉션을 대입한다.
        dir = Camera.main.transform.TransformDirection(dir);
        dir.y = 0;
        chraCtr.Move(dir * speed * Time.deltaTime);       
    }
}

------------------------------------------------------------------------

파티클 사용하기
===[BoomProcess ]=======================================
using UnityEngine;
using System.Collections;
 
public class BoomProcess : MonoBehaviour 
{
    // ENTER  = 부딪힌 시점
    // EXIT = 나가고 난 뒤
    // 인스펙터에서 파티클 프리팹을 연결함
    public GameObject myParticle = null;
 
    
    void OnCollisionEnter(Collision other)
    {
        //Instantiate 는 게임 오브젝트를 반환한다.
        GameObject obj = Instantiate(myParticle);
        // 생성(Instantiate)되는 오브젝트의 위치값을 설정한다.
        obj.transform.position = this.transform.position;
        
        Destroy(gameObject);
    }
}

---------------------------------------------------------------------------



Mass  질량
drag  마찰력
Angulat drag 회전 마찰력














// 오브젝트를 활성화 할때 시작되는 메소드 = OnEnable()

    void OnEnable()
    {
        StopAllCoroutines();
        StartCoroutine("ParticleProcess");
    }






====[클래스와 스트럭쳐의 차이]====================================================


using UnityEngine;
using System.Collections;
 
// 참조와 복사
// 클래스와 스트럭쳐의 차이점
 
public class VectorClass
{
    //생성자
    public VectorClass(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
 
    //일반 함수.
    public void Call()
    {
        Debug.Log("X : " + x);
        Debug.Log("Y : " + y);
 
    }
 
    public float x;
    public float y;
}
 
// 구조체
public struct VectorStruct
{
    //생성자 초기화 할때 사용함
    public VectorStruct(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
 
    //일반 함수.
    public void Call()
    {
        Debug.Log("X : " + x);
        Debug.Log("Y : " + y);
 
    }
 
    public float x;
    public float y;
}
 
public class Class_Struct : MonoBehaviour
{
    void Start()
    {        
        //클래스 사용. 생성자 사용으로 선언과 동시에 값을 대입 해 줌.
        VectorClass myVClass1 = new VectorClass(10, 20);
        myVClass1.Call();// = x : 10
 
        //복사 myVClass1을 참조 하고 있기때문에 
        VectorClass myVClass2 = myVClass1;
        //myVClass1 의 값을 수정한것과 같다.
        myVClass2.x = 1000;
        myVClass1.Call(); // = x : 1000
 
        // 클래스는 복사한 값이 원래 값을 변경
        
        VectorStruct myASturct1 = new VectorStruct(10, 20);
        myASturct1.Call();
 
        //스트럭쳐는 다른 주소를 가지고 있기때문에 값을 다르게 할 수 있다.
        VectorStruct myASturct2 = myASturct1;
        myASturct2.x = 1000;
        myASturct1.Call(); // x : 10
 
        myASturct2.Call(); // x : 1000
        // 스트럭쳐는 복사한 값이 원래값에 영향을 주지 않는다. 
 
    }
}



----------------------------------------------------------------------------

===[프로퍼티 사용법]===========================================================


using UnityEngine;
using System.Collections;
 
public class TestProperty
{
    int count = 10;
 
    // 프로퍼티 사용법
    public int PCount
    {
        get
        {
            return count;
        }
        set
        {
            count = value;
        }
    }
    
 
    public int getCount()
    {
        return 10;
    }
 
    public void setCount(int c)
    {
        count = c;
    }
 
}
 
public class Poperty : MonoBehaviour {
 
 
    // Use this for initialization
    void Start () 
    {
        TestProperty testPRro = new TestProperty();
        // get
        /*
        int result = testPRro.getCount();
        // set
        testPRro.setCount(100);
 
        result = testPRro.getCount();
 
        Debug.Log(result);
 
        */
 
        // int 자료형 변수 result를 만들고 TestProperty 클래스의 count 값을 리턴한다.
        int result = testPRro.PCount;
        Debug.Log(result); // = 10
        // 프로퍼티를 사용하여 count 값을 변경한다.
        testPRro.PCount = 100;
        // 새로 설정한 값을 result 변수에 대입한다.
        result = testPRro.PCount;
        Debug.Log(result); // = 100
        
        
    }
    
 
    
 
    // Update is called once per frame
    void Update () {
    
    }
}

댓글

이 블로그의 인기 게시물

날짜 시간 시간차 시간 계산 하기

코루틴에서 CallBack 함수 적용하기

C++ 언어 퍼센트 구하는 방법 / 기본 언어 퍼센트 구하는 방법