05-17 06:36
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

Script for an Object Touched on Mobile Devices 본문

CG & Video Games/Unity 3D

Script for an Object Touched on Mobile Devices

cinema4dr12 2013. 5. 26. 12:21

using UnityEngine;

using System.Collections;

 

public class ObjectTouched : MonoBehaviour {

public GUIText myText;

private Ray myRay = new Ray();

RaycastHit myHit = new RaycastHit();

 

// Use this for initialization

void Start () {

myText.text = "";

}

 

// Update is called once per frame

void Update () {

 

if(Input.touchCount > 0)

{

if(Input.GetTouch(0).phase.Equals(TouchPhase.Began))

{

myRay = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

if (Physics.Raycast(myRay, out myHit, 100.0f))

{

myText.text = myHit.collider.name.ToString();

}

}

}

 

}

}

'CG & Video Games > Unity 3D' 카테고리의 다른 글

Loading PNG Sequence  (0) 2013.05.26
How to Play Animation Sequence in Unity  (0) 2013.05.26
Script for an Object Clicked - an Alternative Method  (0) 2013.05.26
Script for an Object Clicked  (0) 2013.05.26
Script for Mobile Touch Scree  (0) 2013.05.26
Comments