Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to perform a "click" on Blackberry with Unity?

Discussion in 'BlackBerry' started by jadamspam1, Nov 8, 2013.

  1. jadamspam1

    jadamspam1

    Joined:
    Aug 22, 2013
    Posts:
    6
    Hi all,

    I am trying to develop an app. The main idea is that I have an object (ball with texture) and I wish to perform an action whether the ball is clicked.

    What do I have to use? Something with Raycast and intersect?

    How do you handle the touch support with BlackBerry (LeftClick is working on Android and iOS AFAIR).

    I can't find any topic describing it. And the API is hard to be decoded. I tried many different configurations.
     
  2. PuneetK

    PuneetK

    Joined:
    Sep 2, 2013
    Posts:
    75
    It's the same exact way as you would do with iOS or Android.
    You can use a screen raycaster to detect clicks/touches and use the simple Input class provided by Unity.
     
  3. jadamspam1

    jadamspam1

    Joined:
    Aug 22, 2013
    Posts:
    6
  4. WaterlooErik

    WaterlooErik

    Joined:
    Jul 22, 2013
    Posts:
    89
    This is a basic script I am using to use raycasts to determine touched objects.

    Code (csharp):
    1.     void CheckMenu(Vector2 touchPosition) {
    2.         RaycastHit hit;
    3.         GameObject touchedObject = null;
    4.  
    5.         if (touchPosition.Equals(Vector2.zero) == false) {
    6.             Ray ray = camera.ScreenPointToRay(touchPosition);
    7.             if (Physics.Raycast(ray, out hit, 10.0f)) {
    8.                 touchedObject = hit.transform.gameObject;
    9.                 if (touchedObject != null) {
    10.                     menu[selected].transform.localScale = new Vector3(0.25f, 0.25f, 1.0f);
    11.                     for (selected = 0; selected < menu.Length; ++selected) {
    12.                         if (menu[selected].Equals(touchedObject)) {
    13.                             break;
    14.                         }
    15.                     }
    16.                 }
    17.             }
    18.         }
    19.     }
    touchPosition is passed into the function and I am actually using either Input.mousePosition/B] or Input.GetTouch(0).position as the screen coordinates.

    I'm initializing touchPosition to Vector2.zero hence the check to make sure it's become something else.

    My objects are close to the camera do I'm only projecting 10.0f units into the world to check for collisions.

    If I find a touchedObject, I cycle through the list of my available objects to see which one it was and update the selectedIndex, this part is pretty particular to my application though as this is my menu selection implementation. What you do with the touchedObject is up to you.
     
  5. jadamspam1

    jadamspam1

    Joined:
    Aug 22, 2013
    Posts:
    6
    Sorry for being so rude and not saying "Thank you".

    I think that I found even easier way to check the click.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayButton : MonoBehaviour {
    5.  
    6.     void OnMouseDown(){
    7.         Application.LoadLevel("game");
    8.     }
    9.    
    10. }
     
    Last edited: Nov 26, 2013