Trigger Event with Pressing on a Mesh

Hey guys!

I just have a quick question. I have a small script that allows the player to enter a car. nothing special.
it uses an empty game object with a Cube (Mesh Filter) and if the player is running around in this Mesh and presses “F” he will enter the car. Buuuut, I want to use this script for mobile and as you all know that there is no “F” button on the iphone.

So, my idea is, that you have to tap on the Cube to enter the car instead of pressing “F”
currently the script is working like that (javascript):

function Update()
{
if (Input.GetKeyUp("f")&& isPlayerVisible) //Asign any key you want to enter/operate vehicle.
{
Debug.Log("Driving");

so, how can i replace the Input.GetKeyUp(“f”) with something like Press.GameObject(“EnterCar”) or how ever this will work?

Thanks in advance!
Kev!

Camera.main.ScreenPointToRay(ScreenTouchPosition) will give you a ray pointing through the camera to the position touched on the screen.

Pass the ray into a raycast, then analyse what gets hit. If it’s the car, then get in.

Relevant code:

Ray screenRay = Camera.main.ScreenPointToRay(ScreenTouchPosition);
RaycastHit rayhit;
if(Physics.Raycast(screenRay, out rayhit)){
    if(rayhit.collider.tag == "CarCube"){ //whatever you want to call it
        Debug.Log("Driving");
    }
}

ok, thanks, one more :wink:
now the code looks like this:

    function Update()
    {
    Ray screenRay = Camera.main.ScreenPointToRay(ScreenTouchPosition);
    RaycastHit rayhit;
    if(Physics.Raycast(screenRay, out rayhit)){
        if(rayhit.collider.tag == "doorTriggerLeft")
    {
    Debug.Log("Driving");

but unity says “Assets/Standard Assets/Scripts/Car entering & exiting.js(16,4): UCE0001: ‘;’ expected. Insert a semicolon at the end.”

16,4 is between Ray and screenRay
could you help me with that? :slight_smile: