Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerTouchMove : MonoBehaviour {
  5.     public Sprite Stay;
  6.     public Sprite Move;
  7.     private float x, y;
  8.    
  9.     // Update is called once per frame
  10.     void Update () {
  11.         foreach (Touch touch in Input.touches)
  12.         {
  13.             x = touch.position.x;
  14.             y = touch.position.y;
  15.             Vector3 touchSens = Camera.main.ScreenToWorldPoint(touch.position);
  16.             Vector2 touchPos = new Vector2(touchSens.x, touchSens.y);
  17.            
  18.             if (collider2D == Physics2D.OverlapPoint(touchPos))
  19.                 //if (touch.phase != TouchPhase.Ended)
  20.                 if (Input.touchCount != 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
  21.                 transform.position = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 10f));
  22.                     gameObject.GetComponent<SpriteRenderer>().sprite = Move;
  23.                 } else if (touch.phase == TouchPhase.Ended)
  24.                 gameObject.GetComponent<SpriteRenderer>().sprite = Stay;
  25.         }
  26.     }
  27.    
  28.     void OnCollisionEnter2D(Collision2D coll) {
  29.         if (coll.gameObject.tag == "Siusiaczek")
  30.             Application.LoadLevel(0);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement