Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by moghes · Jan 23, 2013 at 08:32 AM · touch controlstouchpad

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.alt text

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
     {
                 
     }
 }

alt text

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?

tocuhcntrls.jpg (194.2 kB)
insp.jpg (65.1 kB)
Comment
Add comment · Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vonni · Jan 23, 2013 at 11:49 AM 0
Share

Fix the code, so its easier to read

avatar image moghes · Jan 23, 2013 at 01:08 PM 0
Share

can you help me with this, while writing it appears organized.. after posting it appears like this..

avatar image AlucardJay · Jan 23, 2013 at 01:14 PM 1
Share

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.

avatar image moghes · Jan 23, 2013 at 01:15 PM 0
Share

Thanks @$$anonymous$$ $$anonymous$$ay (alucardj) , want to know how to fix this

avatar image AlucardJay · Jan 23, 2013 at 01:38 PM 1
Share

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.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges