Hi,
I m developing an android 2d game , i m moving a camera with touch left , right , up and down when i touch anywhere to the device screen it’s moving.
and i have a sprite , when i click on it shows me a message that i m clicking on sprite.
Here is the code that is attached to the camera:
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
startPos = touch.position;
fingerHold = true;
}
else if (touch.phase == TouchPhase.Moved)
{
endPos = touch.position;
}
else if (touch.phase == TouchPhase.Ended)
{
fingerHold = false;
}
}
if (fingerHold)
{
float deltaX = endPos.x - startPos.x;
float deltaY = endPos.y - startPos.y;
bool horizontal = false;
if (Mathf.Abs(deltaX) > Mathf.Abs(deltaY))
horizontal = true;
if (horizontal)
{
if (deltaX < 0 && transform.position.x < CameraXLimitLeft)
{
transform.Translate(Vector3.left * Time.deltaTime * 20);
}
else if (deltaX > 0 && transform.position.x > CameraXLimitRight)
{
transform.Translate(Vector3.right * Time.deltaTime * 20);
}
}
else
{
if (deltaY < 0 && transform.position.y < CameraYLimitDown)
{
transform.Translate(Vector3.down * Time.deltaTime * 20);
}
else if (deltaY > 0 && transform.position.y > CameraYLimitUp)
{
transform.Translate(Vector3.up * Time.deltaTime * 20);
}
}
}
And this is the script that attached to the sprite.
public GUIText guiTextSprite;
void OnMouseDown()
{
Debug.Log("Test Sprite");
guiTextSprite.text = "Test Sprite";
}
PS: in the sprite there is a polygon collider2d , sprite renderer and rigidbody.
The problem that when i touch the sprite the camera still moves. I want when i touch the sprite the camera stop moving and when i touch anywhere to the screen the camera moves
Thanks for your help