Creating Toggle Switches in Unity!!!

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ม.ค. 2025

ความคิดเห็น •

  • @mrtigeriffic2992
    @mrtigeriffic2992 2 ปีที่แล้ว +2

    Thank you very much for this video. I was looking for a toggle function like this and was able to adapt it to my code.
    Also not used delegations before and will definitely consider them more going forward.

  • @SweetMeethi
    @SweetMeethi 3 ปีที่แล้ว +2

    Great video, very helpful, thank you!

  • @Berndr
    @Berndr 3 ปีที่แล้ว +3

    great video, I struggle with do tween, hope you make a tutorial on how to use it

  • @davegillis9341
    @davegillis9341 4 ปีที่แล้ว +2

    A DOTween tutorial would be helpful, online support is thin on the ground!

  • @Edo4rdo.g
    @Edo4rdo.g 3 ปีที่แล้ว

    i everyone i do the same step as you but when i press the slider handle idk why the background vanish but in the inspector say it's green, some ideas to what can be the problem? thanks in advice

  • @binarium4376
    @binarium4376 3 ปีที่แล้ว +2

    he types faster than me even at 0.5x speed

  • @halogenic
    @halogenic 4 ปีที่แล้ว +1

    Could you use a slider to create a toggle switch? Just make it really small with only two values 0 and 1.

    • @OneWheelStudio
      @OneWheelStudio  4 ปีที่แล้ว +1

      Probably. I’m not 100% sure what the UI experience would be like but from a coding perspective it should be very doable.

  • @psyboyo
    @psyboyo 5 ปีที่แล้ว +5

    PLEASE DoTween tutorials! I bought it on an Humble Bundle, and I'm still to decipher it :D

    • @OneWheelStudio
      @OneWheelStudio  5 ปีที่แล้ว +2

      I'm not a power user for sure, but I use it all time in my personal project! Anything in particular you're working on or want to learn?

    • @psyboyo
      @psyboyo 5 ปีที่แล้ว +1

      @@OneWheelStudio oh just the essentials of DoTween, practical use of it like in this video, to get one started with these little gems that can then be applied in many different and weird ways, I'm sure of it! Your way of explaining and showing these things is really nice and real hands on. Right now I'm working on a vertical 2D block puzzler, trying to hack a way how equal blocks visually merge theirs edges with their equal neighbors... aka Mr Driller style...

    • @OneWheelStudio
      @OneWheelStudio  5 ปีที่แล้ว

      @@psyboyo Awesome. I can do the basics! I'll probably throw in some coroutines too, as Dotween plays nice with them and allows good control.

  • @JustinL1VE
    @JustinL1VE 4 ปีที่แล้ว +1

    Assets\ToggleSwitch.cs(4,7): error CS0246: The type or namespace name 'DG' could not be found (are you missing a using directive or an assembly reference?)
    Please help?!

    • @OneWheelStudio
      @OneWheelStudio  4 ปีที่แล้ว +1

      I suspect you need to add DoTween to your project. Either the free or paid version should work.

    • @JustinL1VE
      @JustinL1VE 4 ปีที่แล้ว +1

      @@OneWheelStudio Thanks!

  • @DJMatureContent
    @DJMatureContent 4 ปีที่แล้ว

    Maybe I'm not understanding something but setting Toggle(isOn) in the OnEnable field does not trigger the expected behavior. If I set the Is On checkbox in the editor, shouldn't the Toggle(isOn) in the OnEnable field see the value and set the color and indicator position? I.E. if I set that value to True then the color should be green and the indicator should be on the right. If I put ToggleColor into the OnEnable field and set the editor Is On value then it works. However, doing the same with MoveIndicator does not. Lastly, you can see this behavior in your video as well-the color starts off Gray then changes once you click the button.

    • @DJMatureContent
      @DJMatureContent 4 ปีที่แล้ว +1

      Ok, so I moved the offX, onX, audioSource to Awake() and call the ToggleColor and MoveIndicator in the OnEnable and it works as expected. Added extra float params to both move and color b/c I didn't want the animations triggered on start. I thought that simply calling Toggle in OnEnable after moving the var declarations to Awake would do the same but it does not.

  • @robinleprince7172
    @robinleprince7172 4 ปีที่แล้ว

    Hello,
    I'm having an issue with the DOColor() animation of the background which fades out.
    Before I click the toggle switch, it is on ON and grey.
    When I flip it, it goes green for a short time before fading out completely and hitting OFF.
    In the inspector, the background animation color works properly, as it switches from green to red.
    But the background simply disappears somewhat lol

    • @OneWheelStudio
      @OneWheelStudio  4 ปีที่แล้ว

      Hmm. That's a bit odd. Not really sure of the cause. But it makes me wonder if the alpha channel of the color is doing something funny. Is it possible that the alpha is going to less than 1 at some point?

    • @robinleprince7172
      @robinleprince7172 4 ปีที่แล้ว

      @@OneWheelStudio I'm new to Unity, how do I check the alpha channel?

    • @robinleprince7172
      @robinleprince7172 4 ปีที่แล้ว

      Oh, alright, it was just the Alpha channel indeed that went to 0.
      Dunno why it did when it was at 255...
      Anyways, thanks a lot!
      Nice video by the way

    • @OneWheelStudio
      @OneWheelStudio  4 ปีที่แล้ว

      @@robinleprince7172 Click on the color in the inspector. It should bring up a color picker. The alpha value should be at the bottom. It is also shown by a white bar at the bottom of the color preview in the inspector.

    • @OneWheelStudio
      @OneWheelStudio  4 ปีที่แล้ว +1

      @@robinleprince7172 Glad that worked. I didn't have any other ideas for solving the problem :P

  • @celperasp
    @celperasp 3 ปีที่แล้ว

    I was very disappointed to find that it wasn't a 3D toggle switch...

  • @Tyrister
    @Tyrister 4 ปีที่แล้ว +1

    Give your scrips for free if you want more views.

  • @Whitesspecial
    @Whitesspecial 4 ปีที่แล้ว

    My animation goes a bit to far any idea why?

    • @OneWheelStudio
      @OneWheelStudio  4 ปีที่แล้ว

      I’d start by double checking the sizes of things and the placement of anchors.

    • @ImGodz0
      @ImGodz0 4 ปีที่แล้ว +4

      onX = backgroundImage.rectTransform.rect.width - toggleIndicator.rect.width + toggleIndicator.anchoredPosition.x;
      That worked for me