Log in or register to post comments

touch 3D Object call a website

October 18, 2011 - 4:20am #1

how can I capture a touch on a 3D object? I must give the object or the AR camera a Collider?

That's what I found.

function Update () {
	if(Input.touchCount > 0)  
	{        
		var touch : Touch = Input.GetTouch(0);
		if(touch.phase == TouchPhase.Began)
        {
		var hit : RaycastHit;
		var cam : Transform = Camera.main.transform;
		var ray: Ray = Camera.main.ScreenPointToRay(touch.position);

		if (Physics.Raycast (ray, hit)) 
		{
			Application.OpenURL ("http://......");

			}

		}

	}
}

At the moment this opens a website no matter where I click. When I click the Back Button. Freezes the app after a short time.

I'm developing with Android and the Samsung Galaxy S.

touch 3D Object call a website

January 3, 2014 - 10:50am #10
Thanks, I will recheck my project. Maybe something is missing.
Regards.

touch 3D Object call a website

January 3, 2014 - 10:21am #9

There should be no affect on RayCasting w/ the upgrade to 2.8.x - check your project to ensure that migration did not corrupt your components or objects.

touch 3D Object call a website

January 3, 2014 - 9:53am #8

Raycast hit was disabled on vuforia 2.8.7 ??

Im using

Physics.Raycast(...)

if(hit.collider.name == "googlePlay"){
              print("touch");
              Application.OpenURL (...); 
}
 
After update to 2.8.7, this code stopped working and I don't know why.
Sorry about my english.
Thanks in advance.

 

touch 3D Object call a website

November 3, 2012 - 9:01am #7

See this example of handling touches on objects, using SendMessage - https://ar.qualcomm.at/content/how-add-touch-listener-3d-object-unity

This approach will activate an OnMouseDown event on the object, which won't throw an error if there is not a custom handler, and enables you to customize the behaviour of touches for each 3D object.

touch 3D Object call a website

November 1, 2012 - 2:27pm #6

Hello, I have all the same problem, please help. When I put this code on any of the items all right object is pressed, the link is a transition, but those objects for which I did not put this script too pressed with an error. How to fix it, how to make objects with script button does not affect the objects without the script (and get enough for one object to throw the script all the objects start pressed)? And when I use CameraDeviceMenu objects that are no longer pressed, and it is necessary that when you click on an empty area of the screen brings up a menu, and clicking on the object there was a transition to the link.

touch 3D Object call a website

October 31, 2012 - 5:25pm #5

Thank you very much! All super works, but I have earned when I called the object is http://www.google.com, simply www.google.com an error.

Logically, I came across the following question, and how to make that not only led to the site but also for example the phone rang on the lot numbers, or email client opened for writing a letter to the address and the like?

touch 3D Object call a website

October 31, 2012 - 4:47pm #4

Hello, sorry for my English, I write through the translator.

I've done as described below, but for me, when you press the 3d object generates an error, it is not a pdf file highlighted and can not be opened O_o. What did I do wrong?

Course of my actions:

1 Create ImageTarget
2 Create a cube with the name www.google.com
3 gave the cube a child ImageTarget
4 created a script selectObject it wrote code that is shown below

"using UnityEngine;
using System.Collections;

public class selectObject: MonoBehaviour {

void Update ()
{
if (Input.GetKeyDown ("escape"))
Application.Quit ();

TapSelect ();
}

void TapSelect ()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay (touch.position);
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
{
Application.OpenURL (hit.collider.gameObject.name);
/ / Debug.Log (hit.collider.gameObject.name);
}
}
}
}

} "

5 threw script on a cube with the name www.google.com

What I have not changed in the code to the end? help please. 

Re: touch 3D Object call a website

October 18, 2011 - 5:42am #3

Thank you, it works! :)

The Camera freezes sometimes. CPU utilization is over 70% and RAM: over 40MB. Is this normal?

I'm getting the following warning message on logcat:

Quote:

WARN/SensorService(124): dropping 1 events on the floor

On what should you look out for when you work with Unity?

Re: touch 3D Object call a website

October 18, 2011 - 4:39am #2

I did something similar. Touching an object loaded a new scene. Here is my working code. Sorry it is in C#.

using UnityEngine;
using System.Collections;

public class selectObject : MonoBehaviour {

void Update () 
	{
	   if (Input.GetKeyDown("escape"))
            Application.Quit();
		
       TapSelect(); 
	}	

void TapSelect() 
	{
   		foreach (Touch touch in Input.touches) 
		{
        	if (touch.phase == TouchPhase.Began) 
			{
            	Ray ray = Camera.main.ScreenPointToRay(touch.position);
            	RaycastHit hit;
            	if (Physics.Raycast (ray, out hit)) 
				{
					Application.LoadLevel(hit.collider.gameObject.name);
                	//Debug.Log(hit.collider.gameObject.name);
            	}
        	}
    	}
	}


 
}

I had the collider set up and object named accordingly. You could make a cube and name it www.google.com
Then you could write

Quote:

Application.OpenURL (hit.collider.gameObject.name);

Log in or register to post comments