Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FlyTouch : MonoBehaviour
- {
- public int currentScore;
- public TextMeshProUGUI textScore;
- Collider2D col;
- void Start()
- {
- col = GetComponent<Collider2D>();
- }
- void Update()
- {
- textScore.text = currentScore.ToString();
- FlyTouchAndScore();
- }
- public void FlyTouchAndScore()
- {
- if (Input.touchCount > 0)
- {
- Touch touch = Input.GetTouch(0);
- Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
- if (touch.phase == TouchPhase.Began)
- {
- Collider2D touchedCollider = Physics2D.OverlapPoint(touchPosition);
- if (col == touchedCollider)
- {
- currentScore += 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement