How to control animation with UI slider?

So I have problem, how I control animation with UI slider, so if I am moving slider forward it plays animation forward and if backwards it plays animation backwards. I have this script, but it doesn’t work anymore in U5 and I have no idea how to make it work with UI slider.

    var sliderPos : float = 0;
    var animationName = "metarig|height";
     
    function Start() {
    animation[animationName].enabled = true;
    animation[animationName].weight = 1;
    }
     
    function OnGUI() {
     
    sliderPos = GUI.HorizontalSlider(Rect(40,40,400,20), sliderPos, 0.0, 1.0);
    animation[animationName].normalizedTime = sliderPos;
     
     
    }

I made it work. :smiley: There is code if someone need help with similar problem.

import UnityEngine.UI;

var obj = GameObject("");
	var animName = obj.GetComponent.<Animation>();
		var whatAnimation = "";
		
var animWrapMode = WrapMode.PingPong;

var SliderPos : float;
var animationSlider = GetComponent(UnityEngine.UI.Slider);

function Start () {
	
	animationSlider.direction = Slider.Direction.LeftToRight;
	animationSlider.minValue = 0;
	animationSlider.maxValue = whatAnimation.Length;
	
	animName[whatAnimation].enabled = true;
	animName[whatAnimation].weight = 1;
	animName[whatAnimation].wrapMode = animWrapMode;
		
	}
	
function Update() {
	animName[whatAnimation].normalizedTime = SliderPos;
	}

function moveSlider(newPos : float) {
	SliderPos = newPos;
}

here’s a simple code for C#

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    
    public class AnimControl : MonoBehaviour {
    	Animation anim;
    	public Slider slider;
    
    	// Use this for initialization
    	void Start () {
    		anim = GetComponent<Animation> ();
    		anim.Play ("SphereAnim"); 
    		anim ["SphereAnim"].speed = 0; 
    	}
   
    	// Update is called once per frame
    	void Update () {
    		anim["SphereAnim"].time = slider.value;
    	}
    }