- Home /
Changing fps touch controls in game
Hello EveryOne! I am developing a game for kids, and I want to give the option for the user to use the desired touch control (change at any time). In a settings page I have two GUI buttons named CTRL1 and CTRL2. Although the change works.
But the touch controls of CIRL2 doesn't work although the joystick touchpads appear.
Several methods I tried...
First:
public var currentFPS:GameObject;
public var currentFPSNumber:Number = 1;
private var MyFPSScript:Behaviour; // Behavior types have .enabled bool var
private var FirstPersonControlScript:Behaviour;
function Start()
{
MyFPSScript = currentFPS.GetComponent(MyFPS);
FirstPersonControlScript = currentFPS.GetComponent(FirstPersonControl);
}
function ShowTouchControls (windowID : int)
{
if(GUI.Button(Rect(windowWidth/7,windowHeight/4,windowWidth/3.5,windowWidth/3.5), "CTRL1" ))
{
showDifferentControls = false;
if(currentFPSNumber == 2)
{
moveTouchPad2GUITexture.enabled = false;
rotateTouchPadGUITexture.enabled = false;
MyFPSScript.enabled = true;
FirstPersonControlScript.enabled = false;
currentFPSNumber = 1;
}
}
if(GUI.Button ......)) // same as for button 1
{
}
}
Here I am using the same FPS control, having two scripts attached, by default MyFPS being enabled only.
The Second method I tried, is Instantiating a new prefab with the second control and the position of the first FPS, and destroying the original.. Both mehtods resulted the same, where I see the change, but controls doesn't accept touch..
Any other methods? or what might be causing this?
can you help me with this, while writing it appears organized.. after posting it appears like this..
For any help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window before posting. When you don't mark your code as code, the text gets html escaped and it gets really hard to reformat it.
I have formatted this one for you. Please check the code is the same as what you have.
Am looking at your problem, but not a person who uses the UnityGUI it is a little confusing, sorry.
Thanks @$$anonymous$$ $$anonymous$$ay (alucardj) , want to know how to fix this
If the GUI items are displaying correctly, you are passing the line if(currentFPSNumber == 2) alright, so firstly check that the correct scripts are being enabled/disabled in the Inspector.
If that is all working fine (myFPS takes swipes and works when enabled, FirstPersonControl at least shows it is enabled when CTRL2 is chosen), then the problem must be in FirstPersonControl where the Inputs are dealt with.
Also personally I would have the FPS/FPC scripts look after enabling their own GUI items, eg. put these in the Start/OnEnable function of the $$anonymous$$yFPS scripts ins$$anonymous$$d of where they are :
moveTouchPad2GUITexture.enabled = false;
rotateTouchPadGUITexture.enabled = false;
and these in the Start/OnEnable function of the FPC scripts ins$$anonymous$$d of where they are :
moveTouchPad2GUITexture.enabled = true;
rotateTouchPadGUITexture.enabled = true;
While you are enabling/disabling the GUI items externally it is impossible to really tell if the correct scripts are being enabled. Anyway that is a side point, but leads to my next debugging suggestion.
Add this function to Both $$anonymous$$yFPS/FPC, uncomment the appropriate line based on what script this function is on :
function OnEnable () {
//Debug.Log( "$$anonymous$$yFPS script was enabled" );
//Debug.Log( "FirstPersonControl script was enabled" );
}
This will at least prove that the correct script is actually being enabled. Run the scene, hit CTRL1/2 and check the console to see if the scripts are being enabled correctly. I'm fairly sure Start also runs on being enabled, so you could just put the Debug there.
If FirstPersonControl is enabling fine and showing a debug, my next suggestion would be look at the way Inputs are managed in FirstPersonControl . After any if(Input..... statement place a debug to see if the Input was indeed detected. Unfortunately this is the way with troubleshooting, just check each stage to see if what you are expecting is actually happening, and Debug.Log is the best tool for this. See what you find.
Your answer
Follow this Question
Related Questions
Get absolute position of touchpad 1 Answer
Rotate with two fingers 0 Answers
Touch.Phase Differences ? 2 Answers
KeyboardOrbit with DualTouchControls 1 Answer
CrossPlatformInputManager.GetAxis() always returns 0 5 Answers