Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

how to convert this script to mouseclick function. i need help on this for memory card game

Discussion in 'Scripting' started by limbp96, May 18, 2018.

?

how to convert this script to mouseclick function. i need help on this for memory card game

  1. -

    0 vote(s)
    0.0%
  2. -

    1 vote(s)
    100.0%
  1. limbp96

    limbp96

    Joined:
    May 5, 2018
    Posts:
    3
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. // TouchManager : Manage device touch
    6. public class TouchManager : MonoBehaviour
    7. {
    8.  
    9.     public LayerMask touchInputMask;
    10.  
    11.     private List<GameObject> touchList = new List<GameObject>();
    12.     private GameObject[] touchesOld;
    13.     private RaycastHit hit;
    14.    
    15.     void Start()
    16.     {
    17.         // Set aspet ratio to 16 : 10
    18.         Camera.main.aspect = 16f / 10f;
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         // When unity editor
    24.         #if UNITY_EDITOR
    25.         {
    26.             touchesOld = new GameObject[touchList.Count];
    27.             touchList.CopyTo (touchesOld);
    28.             touchList.Clear ();
    29.  
    30.             Ray ray = GetComponent<Camera>().ScreenPointToRay (Input.mousePosition);
    31.  
    32.             if (Physics.Raycast (ray, out hit, touchInputMask))
    33.             {              
    34.                 // MemoryCard initilization
    35.                 if(hit.transform.GetComponent<MemoryCard>() != null)
    36.                 {
    37.                     hit.transform.GetComponent<MemoryCard>().Show();
    38.                 }
    39.  
    40.                 GameObject recipient = hit.transform.gameObject;
    41.                 touchList.Add (recipient);
    42.                
    43.                 if (Input.GetMouseButtonDown(0))
    44.                 {
    45.                     recipient.SendMessage ("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
    46.                 }
    47.                 if (Input.GetMouseButtonUp(0))
    48.                 {
    49.                     recipient.SendMessage ("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
    50.                 }
    51.                 if (Input.GetMouseButton(0))
    52.                 {
    53.                     recipient.SendMessage ("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
    54.                 }
    55.             }
    56.  
    57.             foreach (GameObject g in touchesOld)
    58.             {
    59.                 if (!touchList.Contains (g))
    60.                 {
    61.                     //g.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
    62.                 }                          
    63.             }
    64.         } // end of if (Input.GetMouseButton (0) || Input.GetMouseButtonDown (0) || Input.GetMouseButtonUp (0))
    65.         #endif
    66.    
    67.  
    68.         if (Input.touchCount > 0)
    69.         {          
    70.             touchesOld = new GameObject[touchList.Count];
    71.             touchList.CopyTo (touchesOld);
    72.             touchList.Clear ();
    73.  
    74.             foreach (Touch touch in Input.touches)
    75.             {      
    76.                 Ray ray = GetComponent<Camera> ().ScreenPointToRay (touch.position);
    77.            
    78.                 if (Physics.Raycast (ray, out hit, touchInputMask))
    79.                 {              
    80.                     // MemoryCard initilization
    81.                     if(hit.transform.GetComponent<MemoryCard>() != null)
    82.                     {
    83.                         hit.transform.GetComponent<MemoryCard>().Show();
    84.                     }
    85.  
    86.                     GameObject recipient = hit.transform.gameObject;
    87.                     touchList.Add (recipient);
    88.                
    89.                     if (touch.phase == TouchPhase.Began)
    90.                     {
    91.                         recipient.SendMessage ("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
    92.                     }
    93.                     if (touch.phase == TouchPhase.Ended)
    94.                     {
    95.                         recipient.SendMessage ("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
    96.                     }
    97.                     if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
    98.                     {
    99.                         recipient.SendMessage ("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
    100.                     }
    101.                     if (touch.phase == TouchPhase.Canceled)
    102.                     {
    103.                         recipient.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
    104.                     }
    105.                 }
    106.             }
    107.  
    108.             foreach (GameObject g in touchesOld)
    109.             {
    110.                 if (!touchList.Contains (g))
    111.                 {
    112.                     //g.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
    113.                 }                          
    114.             }
    115.         } // end of if (Input.touchCount > 0)
    116.        
    117.         // Smartphone back button : application quit
    118.         if (Input.GetKeyDown (KeyCode.Escape))
    119.         {
    120.             Application.Quit ();
    121.         }
    122.     }
    123. }
     
  2. N00MKRAD

    N00MKRAD

    Joined:
    Dec 31, 2013
    Posts:
    181
  3. limbp96

    limbp96

    Joined:
    May 5, 2018
    Posts:
    3
    erm sorry im new here.im actually creating a memory card game for desktop based. im trying to change the coding into mouseclick function.is it possible?