- Home /
How to dectect Cube (Trigger) is touched
Could anyone can help me to sort out what I like to do with my iPad? I am very new to Unity and JavaScript.
I have several cubes in my scene, which I am using as a trigger.
I want to show a message box when the cubes were touched. I am able to show a message box when a cube is touched but the message box show all the time without detecting the cube is touched.
Could you anyone show me how to detect the cubes are touched in JS?
Here is my code and I think I have to use Trigger touched function rather than Update() function. but I don't know how to build trigger touched function.
function Update(){
for (var event : Touch in Input.touches){ if (event.phase == TouchPhase.Began){ touchDetect = true; for (var touch : iPhoneTouch in iPhoneInput.touches){ touchPosion = touch.position; } OnGUI(); }//end if if (event.phase == TouchPhase.Ended){ touchDetect = false; OnGUI(); }//end if }//end for }//end Update
function OnGUI () {
if(touchDetect){
GUI.TextArea(Rect(0,0,170,190), "Name: Centre for A\nAddress: Court Raod \nTel: +44 (0)20 1236 92"); GUI.Label(Rect(200,200,100,50), touchPosion.ToString()); }//end if }//end OnGUI
Many thanks in advance.
$$anonymous$$aybe this helps: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
Your answer

Follow this Question
Related Questions
Can't click gameobject when over another trigger? 1 Answer
A way for a trigger to detect if anything is in it? 1 Answer
Collide with projection 1 Answer
How to add the right amount of points when my player destroys a gameobject? 0 Answers
Detect a collider/trigger exiting a trigger quickly 0 Answers