Answer the question
In order to leave comments, you need to log in
Why does the UI button fly away on the Z coordinate?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UpDownButtons : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
public Camera cam;
public void OnPointerUp(PointerEventData eventData)
{
gameObject.transform.position = cam.ScreenToWorldPoint (new Vector3 (gameObject.transform.position.x, gameObject.transform.position.y + 6f, 0));
}
public void OnPointerDown(PointerEventData eventData)
{
gameObject.transform.position = cam.ScreenToWorldPoint(new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - 6f, 0));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question