Rasagar/Assets/Viking Village/Scripts/ControlSwitch.cs
2024-08-26 23:07:20 +03:00

49 lines
1.1 KiB
C#

using UnityEngine;
using System.Collections;
public class ControlSwitch : MonoBehaviour {
public KeyCode toggleKey = KeyCode.C;
public GameObject manualController;
public GameObject automaticController;
private bool useAutomaticControl = false;
private const string automaticControlDefaultCMDLineArgument = "-automaticControl";
void Awake()
{
Application.targetFrameRate = 60;
useAutomaticControl = HasCommandLineArgument (automaticControlDefaultCMDLineArgument);
SetControllerState (true);
}
void Update()
{
if (Input.GetKeyDown (toggleKey)) {
Toggle ();
}
}
void Toggle()
{
useAutomaticControl = !useAutomaticControl;
SetControllerState(useAutomaticControl);
}
void SetControllerState(bool useAutomaticControl)
{
manualController.SetActive (!useAutomaticControl);
automaticController.SetActive (useAutomaticControl);
}
bool HasCommandLineArgument(string argument)
{
string[] passedArguments = System.Environment.GetCommandLineArgs ();
foreach (string passedArgument in passedArguments) {
if (passedArgument.Equals(argument))
return true;
}
return false;
}
}