Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerTouchMove : MonoBehaviour {
- public Sprite Stay;
- public Sprite Move;
- private float x, y;
- // Update is called once per frame
- void Update () {
- foreach (Touch touch in Input.touches)
- {
- x = touch.position.x;
- y = touch.position.y;
- Vector3 touchSens = Camera.main.ScreenToWorldPoint(touch.position);
- Vector2 touchPos = new Vector2(touchSens.x, touchSens.y);
- if (collider2D == Physics2D.OverlapPoint(touchPos))
- //if (touch.phase != TouchPhase.Ended)
- if (Input.touchCount != 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
- transform.position = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 10f));
- gameObject.GetComponent<SpriteRenderer>().sprite = Move;
- } else if (touch.phase == TouchPhase.Ended)
- gameObject.GetComponent<SpriteRenderer>().sprite = Stay;
- }
- }
- void OnCollisionEnter2D(Collision2D coll) {
- if (coll.gameObject.tag == "Siusiaczek")
- Application.LoadLevel(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement