Hello, im new to unity and am just trying to get my feet wet and make some basic game elements.
One such element that I am currently working on is a little UI menu that lets the player move and select options within it. To do this I wrote a small simple script to just move the cursor up and down between the possible selections. I used the cursors local y positions (as it is a child of the box).
But the cursor was acting strangely, so while debuging I asked it to print out its local pos y and its global pos y. Both of which were different than the pos y i see in the inspector.
Im sure that I am missing something simple and showing off my noobishness, but I am not sure what.
any help would be appreciated, thanks.
my code
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class DialogChoiceManager : MonoBehaviour {
public GameObject ChoiceManager;
public Text option1;
public Text option2;
public Text option3;
public Text option4;
public Image arrow;
public bool isChoiceBoxOpen;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// this controls the pointer in the dialogchoice box
// we first check to make sure the box is even open
if (isChoiceBoxOpen == true)
{
// check to see if we are at the top of the box.
if (arrow.rectTransform.localPosition.y < 19.0f)
{
option1.text = arrow.transform.localPosition.y.ToString();
option2.text = arrow.transform.position.y.ToString();
// if we are not at the top of the box and the up key is pressed
if (Input.GetKeyUp(KeyCode.UpArrow))
{
// move the arrow up 13 units
arrow.rectTransform.localPosition = new Vector2(arrow.rectTransform.localPosition.x, arrow.rectTransform.localPosition.y + 13.0f);
}
}
// check to see if we are at the bottom of the box.
if (arrow.rectTransform.localPosition.y > -20.0f)
{
// if we are not and the down key is pressed
if (Input.GetKeyUp(KeyCode.DownArrow))
{
// move the arrow down 13 units
arrow.rectTransform.localPosition = new Vector2(arrow.rectTransform.localPosition.x, arrow.rectTransform.localPosition.y - 13.0f);
}
}
}
}
}
screenshot of the problem
