Turning Mouse Input into Touch

Hi,
So I have this script:
using UnityEngine;
using System.Collections;

public class MouseLook : MonoBehaviour {



	public int fireRate;

	public float lookSensitivity = 5f;
	public float xRotation;
	public float yRotation;

	public Rigidbody bullet;


	public Transform barrelEnd1;
	public Transform barrelEnd2;
	public Transform barrelEnd3;
	public Transform barrelEnd4;






	void Start () {

	}



	void Update() {
		xRotation += Input.GetAxis ("Mouse Y") * lookSensitivity;
		yRotation -= Input.GetAxis ("Mouse X") * lookSensitivity;

		xRotation = Mathf.Clamp (xRotation, 0, 0);

		transform.rotation = Quaternion.Euler (xRotation, yRotation, 0);



		if (Input.GetMouseButton (0)) {

			Rigidbody bulletInstance;
		

			bulletInstance = Instantiate (bullet, barrelEnd1.position, barrelEnd1.rotation) as Rigidbody;
			bulletInstance.AddForce (barrelEnd1.forward * fireRate);

	

			bulletInstance = Instantiate (bullet, barrelEnd2.position, barrelEnd2.rotation) as Rigidbody;
			bulletInstance.AddForce (barrelEnd2.forward * fireRate);
		

			bulletInstance = Instantiate (bullet, barrelEnd3.position, barrelEnd3.rotation) as Rigidbody;
			bulletInstance.AddForce (barrelEnd3.forward * fireRate);


			bulletInstance = Instantiate (bullet, barrelEnd4.position, barrelEnd4.rotation) as Rigidbody;
			bulletInstance.AddForce (barrelEnd4.forward * fireRate);

		}


	
	
	}




}

I would like to make it so that instead of using the mouse position to rotate the player, I want to be able to drag my finger of the screen instead.

Any ideas? @Mmmpies
Thanks,

First off do this tutorial

You need to start understanding the EventSystem and start geting your hands dirty with some code. That said it’s fairly straight forward to convert as you script simply appears to rotate the player. I got rid of all the other stuff for testing and if using the UI like this this script will need to be on a panel (which is why I added the player public variable. If you want a fire button you need to add a button to your canvas and trigger it with an OnClick.

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;

public class PointLook : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler {

	public GameObject MyPlayer;

	private float xRotation;
	private float yRotation;
	private bool pointing = false;
	private Vector2 fingerMouse;
	private float rotationSpeed = 5f;

	void Update() {
		if (pointing) {
			yRotation -= (fingerMouse.x / (Screen.width / 2)) * rotationSpeed;
			MyPlayer.transform.rotation = Quaternion.Euler (0, yRotation, 0);
		}
	}

	public void OnDrag(PointerEventData ped)
	{
		if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent<RectTransform> (),
												ped.position, ped.pressEventCamera, out fingerMouse))
			return;
	}

	public void OnPointerDown(PointerEventData ped)
	{
		if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent<RectTransform> (),
												ped.position, ped.pressEventCamera, out fingerMouse))
			return;

		pointing = true;
	}

	public void OnPointerUp(PointerEventData ped)
	{
		pointing = false;
	}
}

I only did this because it interested me though, you really can’t expect people to write scripts for you, not even me.