Hello everyone,
Hopefully, some of you have worked out a solution for this problem in the past. I think this question is self-explanatory; however, I will give you some more details along with the code that I have so far. I want my gameObject to move along the x-axis when I drag my mouse or finger along a button that spans a portion of the screen; it must stay at the same y-axis throughout movement.
Here is a link to a game that has the exact same controls as I want: The Line on the App Store
Below, is the code that I attached to the gameObject that I wanted to affect.
using UnityEngine;
using System.Collections;
public class Drag : MonoBehaviour {
private Vector2 screenPoint;
void OnMouseDrag()
{
Vector2 curScreenPoint = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint);
transform.position = curPosition;
}
}
This code enables me to drag my gameObject around anywhere on the screen, which is nice, but obviously not exactly what I want.
Thanks in advance.