[ HeadLookWalk01.cs ]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeadLookWalk : MonoBehaviour
{
public float velocity = 0.7f;
private CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
Vector3 moveDirection = Camera.main.transform.forward;
moveDirection *= velocity * Time.deltaTime;
moveDirection.y = 0.0f;
controller.Move(moveDirection);
}
}
Time.deltaTime : 프레임 단위의 간격( 이전 프레임과 현 프레임간의 시간)
[ HeadLookWalk02.cs ]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeadLookWalk : MonoBehaviour
{
public float velocity = 0.7f;
private CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
controller.SimpleMove(Camera.main.transform.forward * velocity);
}
}
SimpleMove() : 중력 효과가 적용되며, Time.deltaTime도 적용되는 함수
[ GameControl.cs ]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameControl : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
if(Application.platform == RuntimePlatform.Android)
{
if(Input.GetKey(KeyCode.Escape))
{
// 할꺼 하셈
Application.Quit();
}
}
}
}
[ PhotoFrame.cs]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PhotoFrame : MonoBehaviour {
public string infoText = "Photo!";
public GameObject infoBubble = null;
// Use this for initialization
void Start () {
infoBubble.transform.GetChild(0).GetComponent<TextMesh>().text = infoText;
Renderer infoBubbleRenderer = infoBubble.GetComponent<Renderer>();
infoBubbleRenderer.sortingLayerName = "Default";
infoBubbleRenderer.sortingOrder = 0;
Renderer textRenderer = infoBubble.transform.GetChild(0).GetComponent<Renderer>();
textRenderer.sortingLayerName = "UI";
textRenderer.sortingOrder = 1;
CloseBubble();
}
public void OpenBubble()
{
infoBubble.SetActive(true);
}
public void CloseBubble()
{
infoBubble.SetActive(false);
}
}
[ LookMoveTobyTime01.cs]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class LookMoveTobyTime : MonoBehaviour {
// 몇초 후에 갈 것인지
public float timeToMove = 3.0f;
// 시간 계산용
private float countDown = 0.0f;
// 현재 어떤 바닥을 바라보고 있는지
private GameObject currentObj = null;
// 정확히 어느 지점을 바라봤는지
private Vector3 targetPos;
// 높이는 고정
private float startY = 0.0f;
// 현재 보고 있는 사진
private PhotoFrame viewPhoto = null;
// Use this for initialization
void Start () {
// 높이 고정
startY = Camera.main.transform.position.y;
}
// Update is called once per frame
void Update () {
Transform camera = Camera.main.transform;
Ray ray;
//RaycastHit[] hits;
GameObject hitObject = null;
ray = new Ray(camera.position, camera.rotation * Vector3.forward);
RaycastHit hit;
if(Physics.Raycast (ray, out hit))
{
hitObject = hit.transform.gameObject;
if (hitObject.transform.parent != null) {
if (hitObject.transform.parent.CompareTag ("ground")) {
targetPos = hit.point;
} else
hitObject = null;
}
}
if(currentObj != hitObject)
{
currentObj = hitObject;
countDown = timeToMove;
}
if(currentObj != null)
{
countDown -= Time.deltaTime;
if(countDown < 0.0f)
{
countDown = timeToMove;
transform.position = targetPos;
}
}
float distance = Vector3.Distance(Camera.main.transform.parent.position , transform.position);
if (distance >= 1.35f)
{
Vector3 dir = transform.position - Camera.main.transform.parent.position;
dir.Normalize();
Camera.main.transform.parent.position += dir * Time.deltaTime * 10.0f;
Vector3 pos = Camera.main.transform.parent.position;
Camera.main.transform.parent.position = new Vector3(pos.x , startY , pos.z);
}
}
}
[ LookMoveTobyTime02.cs]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class LookMoveTobyTime : MonoBehaviour {
// 몇초 후에 갈 것인지
public float timeToMove = 3.0f;
// 시간 계산용
private float countDown = 0.0f;
// 현재 어떤 바닥을 바라보고 있는지
private GameObject currentObj = null;
// 정확히 어느 지점을 바라봤는지
private Vector3 targetPos;
// 높이는 고정
private float startY = 0.0f;
// 현재 보고 있는 사진
private PhotoFrame viewPhoto = null;
// Use this for initialization
void Start () {
// 높이 고정
startY = Camera.main.transform.position.y;
}
// Update is called once per frame
void Update () {
Transform camera = Camera.main.transform;
Ray ray;
//RaycastHit[] hits;
GameObject hitObject = null;
ray = new Ray(camera.position, camera.rotation * Vector3.forward);
RaycastHit hit;
if(Physics.Raycast (ray, out hit))
{
hitObject = hit.transform.gameObject;
if (viewPhoto != null)
viewPhoto.CloseBubble();
// 액자 체크
if (hitObject.CompareTag("photo"))
{
viewPhoto = hitObject.GetComponent<PhotoFrame>();
viewPhoto.OpenBubble();
}
if (hitObject.transform.parent != null) {
if (hitObject.transform.parent.CompareTag ("ground")) {
targetPos = hit.point;
} else
hitObject = null;
}
}
if(currentObj != hitObject)
{
currentObj = hitObject;
countDown = timeToMove;
}
if(currentObj != null)
{
countDown -= Time.deltaTime;
if(countDown < 0.0f)
{
countDown = timeToMove;
transform.position = targetPos;
}
}
float distance = Vector3.Distance(Camera.main.transform.parent.position , transform.position);
if (distance >= 1.35f)
{
Vector3 dir = transform.position - Camera.main.transform.parent.position;
dir.Normalize();
Camera.main.transform.parent.position += dir * Time.deltaTime * 10.0f;
Vector3 pos = Camera.main.transform.parent.position;
Camera.main.transform.parent.position = new Vector3(pos.x , startY , pos.z);
transform.GetChild(0).gameObject.SetActive(true);
}
else
{
transform.GetChild(0).gameObject.SetActive(false);
}
}
}
[ AutoFocus.cs]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class AutoFocus : MonoBehaviour {
bool bStartEndInit = false;
// Update is called once per frame
void Update ()
{
if (!bStartEndInit)
{
bStartEndInit = true;
AutoFocusOn ();
}
}
void AutoFocusOn()
{
CameraDevice.Instance.SetFocusMode (CameraDevice.FocusMode.FOCUS_MODE_CONTINUOSAUTO);
}
}
AR 프로젝트 : 카메라 오토포커스 강제 실행