one class for all type of controllers


I would like to develop a game which I can test either on iOS and desktop anytime I run it without having to change the GetInput type everytime.

Is there a code example that checks if I am playing in a tablet or desktop? How can I use this code for the entire calls to the Input in the project?

Thank you!!

You need to use conditional compilation to run platform specific code.

Conditional compilation reference

I think I found a way to sort this out:

I created a class called Controls with a script called ControlScr.

using UnityEngine;
using System.Collections;

public class ControlsSrc : MonoBehaviour
		private  bool _isTouchDevice = false;
		public  bool clickDetected;
		public  Vector3 touchPosition;
		void Awake ()
				if (Application.platform == RuntimePlatform.IPhonePlayer) 
						_isTouchDevice = true;
						_isTouchDevice = false; 
		// Update is called once per frame
		void Update ()
//				clickDetected;
//				touchPosition;
				// Detect click and calculate touch position
				if (_isTouchDevice) {
						clickDetected = (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began);
						touchPosition = Input.GetTouch (0).position;
				} else {
						clickDetected = (Input.GetMouseButtonDown (0));
						touchPosition = Input.mousePosition;

				DontDestroyOnLoad (this.gameObject);

so far, when I need to make a touch or click I call:

			if (ctr.clickDetected) {

la la la...}

and seems to work on pc, havent tried on mobile yet…

I wrote DontDestroyOnLoad on update so the instance can be used everywhere in the program.

Is everything I wrote correct? please help me.