﻿ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MoveObject_withSlider : MonoBehaviour
{

    // Attch this component to a GameObject to move it to a Target Object position with a UI slider.

    // Step1. Add Target GameObject and assign it in the inspector
    // Step2. Add a Slider (values 0-1) and assign it in the inspector    
    // Slider will move GameObject from its starting position to the Target position based on the sliders position.



    /*************************************************************************
* 
* ARConnex
* __________________
* 
*  [2017] - [2020] ARConnex Incorporated 
*  All Rights Reserved.
* 
* NOTICE:  All information contained herein is, and remains
* the property of ARConnex Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to ARConnex Incorporated
* and its suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from ARConnex Incorporated or if used for display in the ARConnex Reality Browser.
*/


    public GameObject target;
    public Slider slider;
    private Vector3 position1;
    private Vector3 position2;

    private void Start()
    {
        position1 = transform.position;
        position2 = target.transform.position;        
        slider.onValueChanged.AddListener(UpdatePosition);
    }

    public void UpdatePosition(float value)
    {
        Vector3 newPosition = Vector3.Lerp(position1, target.transform.position, value);
        transform.position = newPosition;
    }
 }
