Android : Camera 2D Movement android unity

on Friday, August 15, 2014


I m touching a camera in my android device and it moves with touch but i want to limit it's moves in X and Y axis , here is the code that let me move the camera.



using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
public float speed = 0.1F;
void Update() {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
transform.Translate(-touchDeltaPosition.x * speed * Time.deltaTime, - touchDeltaPosition.y * speed * Time.deltaTime, 0);
}
}
}


Thanks for your help


0 comments:

Post a Comment