Search Unity

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.         if (Input.GetMouseButton (0) || Input.GetMouseButtonDown (0) || Input.GetMouseButtonUp (0))
    26.         {
    27.             touchesOld = new GameObject[touchList.Count];
    28.             touchList.CopyTo (touchesOld);
    29.             touchList.Clear ();
    30.  
    31.             Ray ray = GetComponent<Camera>().ScreenPointToRay (Input.mousePosition);
    32.  
    33.             if (Physics.Raycast (ray, out hit, touchInputMask))
    34.             {              
    35.                 // MemoryCard initilization
    36.                 if(hit.transform.GetComponent<MemoryCard>() != null)
    37.                 {
    38.                     hit.transform.GetComponent<MemoryCard>().Show();
    39.                 }
    40.  
    41.                 GameObject recipient = hit.transform.gameObject;
    42.                 touchList.Add (recipient);
    43.                
    44.                 if (Input.GetMouseButtonDown(0))
    45.                 {
    46.                     recipient.SendMessage ("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
    47.                 }
    48.                 if (Input.GetMouseButtonUp(0))
    49.                 {
    50.                     recipient.SendMessage ("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
    51.                 }
    52.                 if (Input.GetMouseButton(0))
    53.                 {
    54.                     recipient.SendMessage ("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
    55.                 }
    56.             }
    57.  
    58.             foreach (GameObject g in touchesOld)
    59.             {
    60.                 if (!touchList.Contains (g))
    61.                 {
    62.                     //g.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
    63.                 }                          
    64.             }
    65.         } // end of if (Input.GetMouseButton (0) || Input.GetMouseButtonDown (0) || Input.GetMouseButtonUp (0))
    66.         #endif
    67.    
    68.  
    69.         if (Input.touchCount > 0)
    70.         {          
    71.             touchesOld = new GameObject[touchList.Count];
    72.             touchList.CopyTo (touchesOld);
    73.             touchList.Clear ();
    74.  
    75.             foreach (Touch touch in Input.touches)
    76.             {      
    77.                 Ray ray = GetComponent<Camera> ().ScreenPointToRay (touch.position);
    78.            
    79.                 if (Physics.Raycast (ray, out hit, touchInputMask))
    80.                 {              
    81.                     // MemoryCard initilization
    82.                     if(hit.transform.GetComponent<MemoryCard>() != null)
    83.                     {
    84.                         hit.transform.GetComponent<MemoryCard>().Show();
    85.                     }
    86.  
    87.                     GameObject recipient = hit.transform.gameObject;
    88.                     touchList.Add (recipient);
    89.                
    90.                     if (touch.phase == TouchPhase.Began)
    91.                     {
    92.                         recipient.SendMessage ("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
    93.                     }
    94.                     if (touch.phase == TouchPhase.Ended)
    95.                     {
    96.                         recipient.SendMessage ("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
    97.                     }
    98.                     if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
    99.                     {
    100.                         recipient.SendMessage ("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
    101.                     }
    102.                     if (touch.phase == TouchPhase.Canceled)
    103.                     {
    104.                         recipient.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
    105.                     }
    106.                 }
    107.             }
    108.  
    109.             foreach (GameObject g in touchesOld)
    110.             {
    111.                 if (!touchList.Contains (g))
    112.                 {
    113.                     //g.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
    114.                 }                          
    115.             }
    116.         } // end of if (Input.touchCount > 0)
    117.        
    118.         // Smartphone back button : application quit
    119.         if (Input.GetKeyDown (KeyCode.Escape))
    120.         {
    121.             Application.Quit ();
    122.         }
    123.     }
    124. }
     
  2. N00MKRAD

    N00MKRAD

    Joined:
    Dec 31, 2013
    Posts:
    210
  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?