# Using a slider to change an object's transform

**URL:** <https://discussions.unity.com/t/using-a-slider-to-change-an-objects-transform/602006>\
**Category:** UGUI\
**Tags:** UGUI\
**Created:** [October 19, 2015, 3:06am UTC](https://discussions.unity.com/t/using-a-slider-to-change-an-objects-transform/602006 "2015-10-19T03:06:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaneburger](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@shaneburger](https://discussions.unity.com/u/shaneburger)\
**Post date:** [October 19, 2015, 3:06am UTC](https://discussions.unity.com/t/using-a-slider-to-change-an-objects-transform/602006/1 "2015-10-19T03:06:07Z")

</div>

I would like to use a slider in the UI to change the transform of an object - either the rotation or location.

It appears that those values are not exposed in a way that I can select them when setting the “On Value Changed” - I select the object, but don’t know what to pick within.

Any idea? Or do I need to expose those properties with a script? If so, how do I do that?

---

<div class="post-metadata">

**Author:** ![Senshi](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/senshi/32/157083_2.png) [@Senshi](https://discussions.unity.com/u/Senshi)\
**Post date:** [October 19, 2015, 5:55pm UTC](https://discussions.unity.com/t/using-a-slider-to-change-an-objects-transform/602006/2 "2015-10-19T17:55:39Z")

</div>

Events like “On Value Changed” can only call functions, not set variables or properties directly. The easiest way would therefore be to just create a simple function, like so:

```csharp
public void SetPositionX(float val){
    Vector3 pos = transform.position;
    pos.x = val;
    transform.position = pos;
}

```

---

<div class="post-metadata">

**Author:** ![shaneburger](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@shaneburger](https://discussions.unity.com/u/shaneburger)\
**Post date:** [October 20, 2015, 2:57am UTC](https://discussions.unity.com/t/using-a-slider-to-change-an-objects-transform/602006/3 "2015-10-20T02:57:20Z")

</div>

So I would just add that script to the object, and then the property SetPositionX would be exposed as a function?

---

<div class="post-metadata">

**Author:** ![Senshi](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/senshi/32/157083_2.png) [@Senshi](https://discussions.unity.com/u/Senshi)\
**Post date:** [October 20, 2015, 3:45am UTC](https://discussions.unity.com/t/using-a-slider-to-change-an-objects-transform/602006/4 "2015-10-20T03:45:33Z")

</div>

Yes, if you add that as a script called “TransformSetters.cs” for example, you can find “TransformSetters \> SetPositionX” in the Inspector’s dropdown.

Some quick terminology though: A property in C# is a member variable that has a getter and setter defined, like this for instance: `public string name {get; private set;}`

Not a big deal, but things like that could lead to confusion. 😉

Good luck!
