does disabled code affect performance

if you have some portions of code disabled say like you have a game with mobile platform controls, as well as computer controls. then when you play it on the computer, do the disabled mobile controls portion have any negative effects besides making the game use more total memory?

do people usually make different versions of games for each platform, or just one dynamic game that picks the correct sections of code to run based on whats its being played on?

As I understand, it won’t affect performance, as it won’t be actively using those sections of script, but it will affect load time, albeit only by a small amount. Short answer, no, I don’t believe so.

It depends on your implementation. You could actually spawn an instance of the appropriate class depending on the control method you’re using and never have the memory footprint required to have instances of control methods that aren’t used on the target platform. Take this example:

using UnityEngine;

public interface IControl
{
	void DetectInput();
}

public class JoystickControl : IControl
{
	public void DetectInput()
	{
		// detect and do stuff with player input from a joystick
		Debug.Log("detecting input from joystick");
	}
}

public class KeyboardAndMouseControl : IControl
{
	public void DetectInput()
	{
		// detect and do stuff with player input from the keyboard and mouse
		Debug.Log("detecting input from keyboard and mouse");
	}
}


public class InputController : MonoBehaviour
{
    public bool useJoystick;  // for demonstrational purposes, replace with target platform sensing logic
    private IControl playerControlMethod;

    void Awake()
    {
        if (useJoystick)
            playerControlMethod = new JoystickControl();
        else
            playerControlMethod = new KeyboardAndMouseControl();
    }

    void Update()
    {
        playerControlMethod.DetectInput();
    }
}

No, if you have code that you don’t use (i.e. you don’t execute it) it has no impact on the performance. Like you said it might result in a slightly larger memory footprint, but code is usually one of the smallest things in your application.

However you can even exclude certain code fragments from being compiled into the final app by using pre-processor tags. If you do so, keep in mind that code in an UNITY_IPHONE seciont literally doesn’t exist when building for any other platform (PC, Android, …). So make sure you don’t build too tight dependencies between classes / methods. One way is in addition to the preprocessor directives to use the strategy pattern like iwaldrop showed you.

That way you can exclude things ment for other platforms but you don’t rely on a certain class.