Unity2014. 8. 5. 15:47


public class PlayerController : MonoBehaviour {


public GUIText countText;

public float moveSpeed = 100f;

public GUIText resultText;

private int count;


// Use this for initialization

void Start () {

count = 0;

countText.text = "count: " + count.ToString ();

resultText.text = "";

}

// Update is called once per frame

void FixedUpdate () {

float h = Input.GetAxis ("Horizontal");

float v = Input.GetAxis ("Vertical");


rigidbody.AddForce (new Vector3 (h, 0f, v) * moveSpeed * Time.deltaTime);

SetCountText ();

}


void OnTriggerEnter(Collider other) {


if(other.gameObject.tag == "Item")

{

//Box Collider 인스펙터에서 Is Trigger 체크해서 활성화!

other.gameObject.SetActive(false);


count += 1;

countText.text = "count: " + count.ToString ();

//Destroy(other.gameObject);

}

//Destroy(other.gameObject);

}

void SetCountText() {

if (count >= 3) {

resultText.text = "Game Over";

countText.text ="";

}

}

}

'Unity' 카테고리의 다른 글

Build 설정 및 실행  (0) 2014.08.06
Rail에서 카메라 이동  (0) 2014.08.05
GUI Text 는  (0) 2014.08.05
플레이어에서 충돌 물체 삭제 처리  (0) 2014.08.05
카메라가 캐릭터 따라감, 위치 고정. rigidbody  (0) 2014.08.05
Posted by 코드버무려
Unity2014. 8. 5. 15:28
  • 보이는 2차원 화면을 수학에서 1사분면으로 노멀화해서 투영한다.
  • 화면 좌측 하단이 0,0 위치다.


Posted by 코드버무려
Unity2014. 8. 5. 15:23

using UnityEngine;

using System.Collections;


public class PlayerController : MonoBehaviour {


public float moveSpeed = 100f;

private int count;


// Use this for initialization

void Start () {

count = 0;

}

// Update is called once per frame

void FixedUpdate () {

float h = Input.GetAxis ("Horizontal");

float v = Input.GetAxis ("Vertical");


rigidbody.AddForce (new Vector3 (h, 0f, v) * moveSpeed * Time.deltaTime);

}

void OnTriggerEnter(Collider other) {


if(other.gameObject.tag == "Item")

{

//Box Collider 인스펙터에서 Is Trigger 체크해서 활성화!

other.gameObject.SetActive(false);


count += 1;

//Destroy(other.gameObject);

}


//Destroy(other.gameObject);

}

}

'Unity' 카테고리의 다른 글

오브젝트를 3개 이상 먹으면 Game Over 처리  (0) 2014.08.05
GUI Text 는  (0) 2014.08.05
카메라가 캐릭터 따라감, 위치 고정. rigidbody  (0) 2014.08.05
오브젝트 별 특성  (0) 2014.08.05
쉐이더  (0) 2014.08.04
Posted by 코드버무려
Unity2014. 8. 5. 14:12




rigidbody [Ctrl + ']하면 유니티 레퍼런스로 넘어간다.


  • Update() : 호출되는 간격이 들쭉날쭉
  • FixedUpdate() : 호출되는 간격이 일정. 물리 연산쪽에 사용
    • Edit > project setting > Inspector에서 확인 가능
  • Player를 아래에 만들어 놓은 Follower 스크립트에 연결한다.
    • 연결방법은 Hierarchy뷰에서 Player를 Inspector뷰에서 Target에 끌어다 놓는다.



using UnityEngine;

using System.Collections;


public class Follower : MonoBehaviour {


public Transform target;

private Vector3 offset;


// Use this for initialization

void Start () {

offset = transform.position;    // 현재 위치

}

// Update is called once per frame

void Update () {

transform.position = target.position; // 바로 어께 위에서 따라 감 

transform.position = target.position + offset;

}

}

'Unity' 카테고리의 다른 글

GUI Text 는  (0) 2014.08.05
플레이어에서 충돌 물체 삭제 처리  (0) 2014.08.05
오브젝트 별 특성  (0) 2014.08.05
쉐이더  (0) 2014.08.04
중력을 추가 Physics.gravity.y  (0) 2014.08.04
Posted by 코드버무려
Unity2014. 8. 5. 11:42
  1. Plane 오브젝트 특성을 제가 좀 드릴께요.
    1. 보통은 성능을 위해서 한 방향에서만 그려요.
    2. -1 값을 주면 뒤집는 효과를 
    3. 기본값은 10미터 x 10m
  2. Directional Light는 태양같은 것이라
    1. 각도가 중요하다.
    2. 위치값은 의미가 없다.


Posted by 코드버무려