GetAxisRaw() Ignoring Second Item

What I have is a list of gameobjects that I have attached to the area. The 3 gameobjects are then able to be “cycled” through by the up and down arrows. The issue I’m having is that the key strokes appear to be too sensitive and the input is skipping over the middle item. I can toggle back and forth between item 1 and item 3 but item 2 only gets selected if I get a magic tap on it. See snippet.

void Update () 
	{
	
		if(Input.GetAxisRaw("Vertical") > 0.9)
		{
			OnSelected(false, Manager[currentMenuItem],speed);
			currentMenuItem--;
			
			if(currentMenuItem <0)
			{
				currentMenuItem = 0;
				
			}
			
			OnSelected(true, Manager[currentMenuItem],speed);
			Yield();
		}
		else if (Input.GetAxisRaw("Vertical") < -0.9)
		{
			OnSelected(false, Manager[currentMenuItem],speed);
			currentMenuItem++;
							
			if(currentMenuItem >= Manager.Length)
			{
				currentMenuItem = Manager.Length-1;
			}
			
			OnSelected(true, Manager[currentMenuItem],speed);
			Yield();
		}

	}

So once I saw this problem, I setup a Yield function to delay it a certain amount of time. In this case, .25f seconds to prevent it skipping over but it does not appear to be working. See the following:

IEnumerator Yield()
	{
		yield return new WaitForSeconds(timedelay);
	}
    

What am I doing wrong here to not get a delay?

Could I try to simplify this for you? It may be that the GetAxisRaw is updating too fast and currentMenuItem is increasing and decreasing too fast. Perhaps try it like this instead?

void Update () 
{
	if (Input.GetButtonDown("Vertical")) {
		
		OnSelected(false, Manager[currentMenuItem],speed);
		
		currentMenuItem += (Input.GetAxisRaw("Vertical")) * -1;
		currentMenuItem = Mathf.Clamp(currentMenuItem, 0, (Manager.Length - 1));
		
		OnSelected(true, Manager[currentMenuItem],speed);
	}
}

Not sure if that will work. :stuck_out_tongue:

Hope that helps, Klep