Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Mokenister · Feb 21, 2016 at 09:30 AM · c#androiduijoystickui image

Android joystick doesn't work after 2nd level >.>

So I just made this script for android joystick, works perfectly tested and approved on my phone. But there is one thing though -- The joystick magically stops working after 2nd level, even though I never changed a single thing. To make sure I haven't changed anything, I made another script, the same as the previous one. Still doesn't work ._. Weirdest thing is that it won't even move when I make a script that would literally only move the joystick when I click on it. Is something altering it in my scene or is it just aliens? Can someone please help me with this it's driving me crazy >.< Here's the script if it helps at all
private Image bgImg; private Image joystickImg; private Vector3 inputVector;

 private void Start()
 {
     bgImg = GetComponent<Image>();
     joystickImg = transform.GetChild(0).GetComponent<Image>();
 }

 public virtual void OnPointerDown(PointerEventData ped)
 {
     OnDrag(ped);
 }
 public virtual void OnPointerUp(PointerEventData ped)
 {
     inputVector = Vector3.zero;
     joystickImg.rectTransform.anchoredPosition = Vector3.zero;
 }
 public virtual void OnDrag(PointerEventData ped)
 {
     Vector2 pos;
     if (RectTransformUtility.ScreenPointToLocalPointInRectangle(bgImg.rectTransform
         , ped.position
         , ped.pressEventCamera
         , out pos))
     {
         pos.x = (pos.x / bgImg.rectTransform.sizeDelta.x);
         pos.y = (pos.y / bgImg.rectTransform.sizeDelta.y);

         inputVector = new Vector3(pos.x * 2 + 1, 0, pos.y * 2 - 1);
         inputVector = (inputVector.magnitude > 1.0f) ? inputVector.normalized : inputVector;

         // Move Joystick IMG
         joystickImg.rectTransform.anchoredPosition = new Vector3(inputVector.x * (bgImg.rectTransform.sizeDelta.x / 2) , inputVector.z * (bgImg.rectTransform.sizeDelta.y / 2));
     }
 }
 public float Horizontal()
 {
     if (inputVector.x != 0)
         return inputVector.x;
     else
         return Input.GetAxis("Horizontal");
 }
 public float Vertical()
 {
     if (inputVector.x != 0)
         return inputVector.z;
     else
         return Input.GetAxis("Vertical");
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Eno-Khaon · Feb 21, 2016 at 10:48 AM

It's a little hard to know for certain, but from what I can see, the script appears to not require any editor-defined variables, so I'll make a few guesses here:

I don't see DontDestroyOnLoad used in your script. Do you currently have multiple scenes for your levels and, if so, is this script present in all of them?

If that's not the problem, are you doing anything unusual when changing scenes/levels? Are you adding or removing content between levels which may result in this script being swept out of the scene at the time?

If that's still not enough, then any further information you can provide which may prove relevant would be great!

Comment
Add comment · Show 2 · Share
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 Mokenister · Feb 21, 2016 at 08:47 PM 0
Share

Well, It's present in all my scenes but it only works in scene Level1Easy, Level1Hard, Level2Easy and Level2Hard. Other levels it doesn't even react on my finger where it's supposed to move the joystick at the very least. It's like a still image even though it's the exact same prefab from level1Easy where it works. I don't know what's DontDestroyOnLoad but I'm guessing I don't need it since there is most likely a thing in my other levels that would cause the script not to work at all. I will mess around with it for a bit more and see if there's something that should be fixed. By the way, I tried making an entire new script and button and canvas for the new level, it still doesn't work, therefore it must be either the script that has some weird commands in it or a gameObject in those levels >.< I'll see if I can do something

avatar image Mokenister · Feb 21, 2016 at 10:19 PM 0
Share

I just tried DontDestroyOnLoad and it didn't fix it :( Also, to make sure everything is properly attached I checked everything while I'm in game mode and sure enough, everything was just like it's supposed to be. The canvas might have something on it so it makes it so I can't touch the canvas objects because there's something above it? I have no idea this is so weird

avatar image
0

Answer by RodrigoGomes · May 02, 2016 at 03:02 AM

Man, i am having the same problem with the same script!! There is no reason not to work, i didnt change a thing!! what was your solution??

Comment
Add comment · Share
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

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

117 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i make my player look at the same direction where its moving? [JOYSTICK ANDROID] 0 Answers

Using the free touchscreen Joystick my code cant detect the joystick 0 Answers

RectTransform Left Right Bottom Top 0 Answers

How can avoid my player to jump twice in the air? 0 Answers

UnityEngine.UI and UnityEngine.EventSystem do not work, what do I do? 1 Answer


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