Proper way to disable transform script?

I have a basic transform script that rotates a 3D object, it’s a 3D medical DICOM “image” of a skull.

I have set up slider controls, to adjust brightness and other stuff.

Now when I click and move the thumb of the slider control, my transform script is still in effect and is rotating the 3D skull, as I scrub back and forth the thumb of the slider.

What is the proper way to disable the transform script or script action, until I stop using the slider?

I know how to enable/disable stuff from Unity3D environment…

I need to disable the transform script when I am using the slider. When I stop using the slider, I want to enable script.

Did you even click the link from @ ? It is exactly what you are asking for.

When I click the slider, I want the script turned off.
When I release the mouse button, I want the script turned on.
I know how to write the script to turn it on and off…that’s not the issue…
I need to turn it off when I actually click on the slider, there is no “mouse down” event on the slider, at least that I know of. And no “mouse up” event on the slider.

https://stackoverflow.com/questions/44700850/how-to-add-onpointerdown-listener-to-slider-handle-in-unity-c

This is what I need…

But it doesn’t tell how to use #2 method…I created the custom script file of slider…
But how do I add the custom slider to the canvas?

How do I use a Custom Slider …like below…?
I don’t mean how to create the script file, how do I add this slider to a canvas in Unity3D like a regular slider?

Declare a new class that inherits from Slider class and overriding the OnPointerDown() method like this:

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class CustomSlider: Slider
{
public override void OnPointerDown(PointerEventData eventData)
{
base.OnPointerDown(eventData);

// Your code here
}
}

https://docs.unity3d.com/ScriptReference/UI.Slider.html

RTFM. Check out the OnPointerEnter and OnPointerExit. (Or OnPointerDown and OnPointerUp if you want enable/disable only on click).

Just write your class and attach it like a normal Slider on the GameObject instead of a normal Slider. I don’t understand what you don’t understand.

1 Like

How do I get the derived class of the slider to appear in the Unity3D work space viewport?

Well, probably you should go back to the basic tutorials. You’re clearly not ready to work on your own yet.

Insert a slider, delete the old slider script, attach your own derived script.

I have

public class CustomSlider : Slider
{
......
public override void OnPointerDown(PointerEventData eventData)
{
......
}
}```

And?

You say to attach it to a GameObject…which one?

To the canvas? I tried, when I run app, the derived slider does not show up.
Dragging to Canvas, #1, adds it as a component of Canvas, but it does not appear as a child slider node of canvas, nor does it appear in 2D viewport, #2, so that I can adjust its location etc…

I understand derived classes…etc…I am familiar with C#…so that’s not the issue.

I understand how to attach scripts/classes to objects, that’s not the issue…

It’s a slider, a derived one, so I can’t just attach this to anything per say, and expect to see the slider when I run the app.

I hope my quandary makes sense…

Okay I will go full beginner:

  • Select one of your existing sliders on the scene.
  • look for the “Slider” component
  • Delete it
  • Add your own Slider script
  • change the parameters to your liking
  • rinse and repeat

Is there a way to get the derived slider to appear in the Unity3D scene view port?

Oh…didn’t know I could do that…

That’s what I was trying to do…thanks a lot, it works.

1 Like

Please delete the attachment and put your code in code tags. You can find the button in the toolbar when you’re editing your post.

that is, when I run the app, and try to drag the slider thumb, it does not move.

The custom slider appears in scene hierarchy and scene viewport, with child property nodes like a normal slider has…