일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- nodeJS
- probability
- Statistics
- 통계
- 확률
- 김양재
- c++
- 주일설교
- Artificial Intelligence
- 인공지능
- 데이터 과학
- 김양재 목사
- data science
- WebGL
- Deep learning
- 빅 데이타
- Machine Learning
- 몽고디비
- 빅데이터
- 김양재 목사님
- openCV
- Big Data
- MongoDB
- 딥러닝
- R
- No SQL
- 우리들교회
- 빅데이타
- 빅 데이터
- node.js
- Today
- Total
Scientific Computing & Data Science
Script for Touch & Drag an Object 본문
using UnityEngine;
using System.Collections;
public class DragObject : MonoBehaviour {
private Ray myRay = new Ray();
RaycastHit myHit = new RaycastHit();
[SerializeField]
private float _horizontalLimit = 2.5f;
private float _verticalLimit = 2.5f;
private float dragSpeed = 0.005f;
private Transform cachedTransform;
private Vector3 startingPos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.touchCount > 0)
{
Vector2 deltaPosition = Input.GetTouch(0).deltaPosition;
//Switch through touch events
switch(Input.GetTouch(0).phase)
{
case TouchPhase.Began:
myRay = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(myRay, out myHit, 100.0f))
cachedTransform = myHit.collider.transform;
break;
case TouchPhase.Moved:
Drag(deltaPosition);
break;
case TouchPhase.Ended:
break;
}
}
}
/// <summary>
/// Drags the object.
/// </summary>
/// <param name='deltaPosition'>
/// Delta position.
/// </param>
void Drag(Vector2 deltaPosition)
{
cachedTransform.position = new Vector3(Mathf.Clamp((deltaPosition.x * dragSpeed) + cachedTransform.position.x,
startingPos.x - _horizontalLimit, startingPos.x + _horizontalLimit),
Mathf.Clamp((deltaPosition.y * dragSpeed) + cachedTransform.position.y,
startingPos.y - _verticalLimit, startingPos.y + _verticalLimit),
cachedTransform.position.z);
}
}
'CG & Video Games > Unity 3D' 카테고리의 다른 글
Sending Commands Using RPC (0) | 2013.05.26 |
---|---|
Script for Network Instantiate(JS) (0) | 2013.05.26 |
Dynamic Images (0) | 2013.05.26 |
VertextLit Shader (0) | 2013.05.26 |
Display Normal Shader (0) | 2013.05.26 |