按钮位置上而是跳到其他地方
public class movetab : MonoBehaviour
{
public GameObject moveitem;
public GameObject otherbutton1;
public GameObject otherbutton2;
public GameObject otherbutton3;
public GameObject otherbutton4;
private Vector3 otherbuttondatestore1;
private Vector3 otherbuttondatestore2;
private Vector3 otherbuttondatestore3;
private Vector3 otherbuttondatestore4;
public void Start()
{
RectTransform otherbuttondate1 = otherbutton1.GetComponent<RectTransform>();
RectTransform otherbuttondate2 = otherbutton2.GetComponent<RectTransform>();
RectTransform otherbuttondate3 = otherbutton3.GetComponent<RectTransform>();
RectTransform otherbuttondate4 = otherbutton4.GetComponent<RectTransform>();
otherbuttondatestore1 = otherbuttondate1.anchoredPosition;
otherbuttondatestore2 = otherbuttondate2.anchoredPosition;
otherbuttondatestore3 = otherbuttondate3.anchoredPosition;
otherbuttondatestore4 = otherbuttondate4.anchoredPosition;
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore1;
}
void Update()
{
RectTransform otherbuttonRect = otherbutton1.GetComponent<RectTransform>();
otherbuttondatestore1 = otherbuttonRect.anchoredPosition;
if (Input.GetKey(KeyCode.A))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore1;
}
if (Input.GetKey(KeyCode.B))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore2;
}
if (Input.GetKey(KeyCode.C))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore3;
}
if (Input.GetKey(KeyCode.D))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore4;
}
}
}
public class movetab : MonoBehaviour
{
public GameObject moveitem;
public GameObject otherbutton1;
public GameObject otherbutton2;
public GameObject otherbutton3;
public GameObject otherbutton4;
private Vector3 otherbuttondatestore1;
private Vector3 otherbuttondatestore2;
private Vector3 otherbuttondatestore3;
private Vector3 otherbuttondatestore4;
public void Start()
{
RectTransform otherbuttondate1 = otherbutton1.GetComponent<RectTransform>();
RectTransform otherbuttondate2 = otherbutton2.GetComponent<RectTransform>();
RectTransform otherbuttondate3 = otherbutton3.GetComponent<RectTransform>();
RectTransform otherbuttondate4 = otherbutton4.GetComponent<RectTransform>();
otherbuttondatestore1 = otherbuttondate1.anchoredPosition;
otherbuttondatestore2 = otherbuttondate2.anchoredPosition;
otherbuttondatestore3 = otherbuttondate3.anchoredPosition;
otherbuttondatestore4 = otherbuttondate4.anchoredPosition;
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore1;
}
void Update()
{
RectTransform otherbuttonRect = otherbutton1.GetComponent<RectTransform>();
otherbuttondatestore1 = otherbuttonRect.anchoredPosition;
if (Input.GetKey(KeyCode.A))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore1;
}
if (Input.GetKey(KeyCode.B))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore2;
}
if (Input.GetKey(KeyCode.C))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore3;
}
if (Input.GetKey(KeyCode.D))
{
RectTransform imageRect = moveitem.GetComponent<RectTransform>();
imageRect.anchoredPosition = otherbuttondatestore4;
}
}
}