touch input analog with touch swipe fps camera
I am making a fps horror game which is having a analog which i already built and working and i also made touch swipe for camera but the problem is when i touch at the analog which is a UI image the camera starts to rotate which i dont want .. how can i fix this ? i tried this also "if (tch.position.x > Screen.width / 2)" but the out come is same.. any fix ?? My code : Swipe Camera code = if (Input.touchCount > 0) { foreach (Touch tch in Input.touches) {
if (tch.position.x > Screen.width / 2) {
touchX = Input.GetTouch(1).deltaPosition.x * Time.deltaTime * touchSpeed;
touchY += Input.GetTouch(1).deltaPosition.y * Time.deltaTime * touchSpeed;
touchY = Mathf.Clamp(touchY, -90, 90);
mouseX = touchX;
mouseY = touchY;
transform.Rotate(0f, touchX, 0f);
cam.transform.localRotation = Quaternion.Euler(-touchY, 0f, 0f);
}
}
Analog Code = void Start () {
bgImage = GetComponent<Image>();
jImage = transform.GetChild(0).GetComponent<Image>();
analogMov = Vector3.zero;
}
public virtual void OnDrag(PointerEventData pData)
{
Vector2 jPos = Vector2.zero;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(bgImage.rectTransform,
pData.position,
pData.pressEventCamera,
out jPos))
{
jPos.x = (jPos.x / bgImage.rectTransform.sizeDelta.x);
jPos.y = (jPos.y / bgImage.rectTransform.sizeDelta.y);
float posxx = (bgImage.rectTransform.pivot.x == 1) ? jPos.x * 3 + 1 : jPos.x * 3 - 1;
float posyy = (bgImage.rectTransform.pivot.y == 1) ? jPos.y * 3 + 1 : jPos.y * 3 - 1;
analogMov = new Vector3(posxx, 0, posyy);
analogMov = (analogMov.magnitude > 1) ? analogMov.normalized : analogMov;
jImage.rectTransform.anchoredPosition = new Vector3(analogMov.x * (bgImage.rectTransform.sizeDelta.x / 3),
analogMov.z * (bgImage.rectTransform.sizeDelta.y / 3));
}
}
public virtual void OnPointerDown(PointerEventData pData)
{
OnDrag(pData);
}
public virtual void OnPointerUp(PointerEventData pData)
{
analogMov = Vector3.zero;
jImage.rectTransform.anchoredPosition = Vector3.zero;
}
}
Answer by maxgtp2 · Feb 21, 2018 at 02:57 AM
Help me? I need script to look with the camera by swiping my finger on the screen for a third person or first person game. I'm a beginner and I do not know C # very well. Game Stile FPS GUN