RayCasting and Input.GetTouch?

Below I have One RayCast that’s active at all times. My goal, is to “instantiate” raycasts whenever a touch screen command is triggered. The Raycast then hits whatever gameObject I desired it to. All the code below is to the best of my knowledge about RayCasting and it’s partial implementation for pc testing.Please help?

public static bool Right;
	public static bool Left;
	public static bool Jump;
	public static bool Action;
	
	void Update()
	{
		Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
		Debug.DrawRay(ray.origin, ray.direction * 10, Color.red);
		RaycastHit hit;
		
		if (Physics.Raycast(ray, out hit) == true)
		{
			Debug.DrawRay(ray.origin, ray.direction * 10, Color.green);
			
			if (hit.transform.gameObject.name == "Right"  Input.GetMouseButton(0))
			{
				Right = true;
			}
			else if (hit.transform.gameObject.name == "Right"  Input.GetMouseButton(0) == false)
			{
				Right = false;
			}
			
			if (hit.transform.gameObject.name == "Left"  Input.GetMouseButton(0))
			{
				Left = true;
			}
			else if (hit.transform.gameObject.name == "Left"  Input.GetMouseButton(0) == false)
			{
				Left = false;
			}
		}
	}
}

Okay so I’ve been doing some studies on Input.Touch. I’m still fairly green at this. At this point I have a single RayCast emitting when I tap the screen. How can I emit multiple ray casts to press multiple controls at one time?

if (Input.touchCount > 0)
		{	
			if (Input.GetTouch(0).phase == TouchPhase.Began)
			{
				Ray ray = Camera.mainCamera.ScreenPointToRay(Input.GetTouch(0).position);
				Debug.DrawRay(ray.origin, ray.direction * 10, Color.red);
				RaycastHit hit;
				
				if (Physics.Raycast(ray, out hit) == true)
				{
					Debug.DrawRay(ray.origin, ray.direction * 10, Color.green);
					
					if (hit.transform.gameObject.name == "Right")
					{
						Right = true;
					}
					
					if (hit.transform.gameObject.name == "Left")
					{
						Left = true;
					}
				}
			}
		}

Hey guys, just wondering if anyone could provide some hints to me. I’m an aggressively eager learner and just need some guidance, thanks.

Well what you do is possible so what do you want help with?

Thank you for offering a hand BFGames.

At the current time, I’m play testing this script on my kindle fire. As you can see, I have two gameObjects that function as buttons. I can tap anywhere upon the screen and a RayCast is emitted. However, if I were to tap two fingers at one time (both of which on a separate button), only one function will be activated. This situation leads me to believe I need two RayCasts, but does that mean I need to apply a new RaycastHit?

You need two ray casts then yes. But at the moment you also only check for Input number [0], you also need to check for 1 then.