Advertisement
Guest User

Script 1

a guest
Feb 23rd, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. public class FlyTouch : MonoBehaviour
  2. {
  3.     public int currentScore;
  4.     public TextMeshProUGUI textScore;
  5.     Collider2D col;
  6.  
  7.     void Start()
  8.     {
  9.         col = GetComponent<Collider2D>();        
  10.     }
  11.  
  12.     void Update()
  13.     {
  14.         textScore.text = currentScore.ToString();
  15.         FlyTouchAndScore();  
  16.  
  17.     }
  18.     public void FlyTouchAndScore()
  19.     {      
  20.         if (Input.touchCount > 0)
  21.         {  
  22.             Touch touch = Input.GetTouch(0);
  23.             Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);        
  24.             if (touch.phase == TouchPhase.Began)
  25.             {        
  26.                 Collider2D touchedCollider = Physics2D.OverlapPoint(touchPosition);                
  27.                 if (col == touchedCollider)
  28.                 {
  29.                     currentScore += 1;
  30.                    
  31.                 }
  32.             }    
  33.         }    
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement