Unity2014. 8. 10. 16:35

고정된 카메라가 앞에 놓여 있는 물체 움직임을 추적하며 상하좌우로 회전하게 하려면

http://docs.unity3d.com/ScriptReference/Transform-rotation.html


using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public float smooth = 2.0F;
    public float tiltAngle = 30.0F;
    void Update() {
        float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
        float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
        Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
        transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
    }
}


예제 코드를 테스트하지 않고 수정하여 사용했습니다.

using UnityEngine; using System.Collections; public class OverWatch : MonoBehaviour { public Transform targetCar; private Vector3 offset; public float smooth = 2.0F; public float tiltAngle = 30.0F; // Use this for initialization void Start () { //offset = transform.position; offset.x = this.targetCar.position.x; offset.y = this.targetCar.position.y; } // Update is called once per frame void Update () { //transform.position = target.position + offset; float tiltAroundY = (offset.x - this.targetCar.position.x) * tiltAngle; // ㄱ float tiltAroundX = (offset.y - this.targetCar.position.y) * tiltAngle; // ㄴ Quaternion target = Quaternion.Euler(tiltAroundX, tiltAroundY, 0); // ㄷ transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth); //transform.rotation *= target; offset.x = this.targetCar.position.x; offset.y = this.targetCar.position.y; // ㅁ } }




원하는 방향으로 회전하는 결과를 얻을 수 없었습니다. 하는 중에  LookAt함수를 찾았고 ㄱ~ㅁ까지 한 줄로 바꿀 수 있었습니다.

transform.LookAt (this.targetCar.position);


'Unity' 카테고리의 다른 글

유니티 2D 스프라이트  (0) 2014.08.07
Animator 애니메이터 (매카님) 에서 지원하는 파라미터  (0) 2014.08.07
Ray 쏘아 오브젝트 삭제  (0) 2014.08.06
유니티 물체 배치  (0) 2014.08.06
Trail Renderer  (0) 2014.08.06
Posted by 코드버무려
Unity2014. 8. 7. 18:06


유니티 애세[스토어 카테괴에서 완성된 프로젝트를 확인하고

"Unity Projects:"라 붙은 것은 유니티사에서 배포하는 예제다.

임포트 하기 전에 가급적 튜 프로젝트를 만들어서 임포트한다.

파일을 import하고 재일 먼저 scene를 찾는다.




  • nGUId에서
    • Panel은 드로우콜 횟수를 낮추기 위해(성능을 높이기 위해) 있다.
      • 그래서     한 번에 모두 그린다.
    • 여러 카메라에서 depth 값이 작은 것이 먼저 그려진다.


  1. 스파리이트 이미지를 잘라주기 : 아틀라스
  2. 스프라이트가 합쳐진 한장 이미지를 에셋 폴더로 가져간다.
  3. 크릭하면 인스펙터뷰에서 TextureType를 Advanced로 설정 아래아래에 Sprite Editor 버튼이 나온다.
  4. 스프라이트 에디터 크릭하고 화면 좌측 상단 슬라이스 버튼을 눌러주고 우측에서 apply하면 잘라준다.
  5. 이 과정을 거쳐 만들어진 각각 이미지를 끌어놓기로 하이어라키 뷰에 가져다 놓고 사용할 수 있다.

Posted by 코드버무려
Unity2014. 8. 7. 13:28

유한 상태 모델과 연관한 코딩



using UnityEngine;

using System.Collections;


public class Move : MonoBehaviour {


public Animator animator;

// getControl 로 자기자신을 가지고 올 수 있고

// 여기에 하이라키 뷰에서 자기자신을 드래그해서 가져올 수도 있다.


// Update is called once per frame

void Update () {


if(Input.GetMouseButtonDown(0))

{ // 애니메이터 (매카님) 에서 지원하는 파라미터

animator.SetBool("Move", true);

}


if(Input.GetMouseButtonDown(1))

{

animator.SetBool("Move", false);

}

}

}

'Unity' 카테고리의 다른 글

LookAt 함수. 고정된 카메라 회전. 감시카메라  (0) 2014.08.10
유니티 2D 스프라이트  (0) 2014.08.07
Ray 쏘아 오브젝트 삭제  (0) 2014.08.06
유니티 물체 배치  (0) 2014.08.06
Trail Renderer  (0) 2014.08.06
Posted by 코드버무려
Unity2014. 8. 6. 16:14


  • if(hit.transform.tag == "Item") 를 적용시키려면 사라짐을 적용할 오브젝트 테그에 "Item"테그를 설정해주어야 한다.




using UnityEngine;

using System.Collections;


public class ShootRay : MonoBehaviour {


public float rayDistance = 100f;


// Update is called once per frame

void Update () {

if(Input.GetMouseButton(0)) {// 0은 왼쪽버튼, 스마트폰에서 터치.

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //카메라에서 레이를 쏜다.

RaycastHit hit;


if (Physics.Raycast(ray, out hit, rayDistance))

{

if(hit.transform.tag == "Item")         ///   

Destroy(hit.transform.gameObject);

}

}

}

}

'Unity' 카테고리의 다른 글

유니티 2D 스프라이트  (0) 2014.08.07
Animator 애니메이터 (매카님) 에서 지원하는 파라미터  (0) 2014.08.07
유니티 물체 배치  (0) 2014.08.06
Trail Renderer  (0) 2014.08.06
Trail Renderer  (0) 2014.08.06
Posted by 코드버무려
Unity2014. 8. 6. 16:12



Ctrl + D : 복사

Ctrl + 각 축: 자신 크기 만큼 이동;

Ctrl + 큐브 정점을 클릭하면 스냅 기동 작동.

'Unity' 카테고리의 다른 글

Animator 애니메이터 (매카님) 에서 지원하는 파라미터  (0) 2014.08.07
Ray 쏘아 오브젝트 삭제  (0) 2014.08.06
Trail Renderer  (0) 2014.08.06
Trail Renderer  (0) 2014.08.06
Build 설정 및 실행  (0) 2014.08.06
Posted by 코드버무려