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

public class ExampleObject : MonoBehaviour
{
    public float speed;
    private Vector2 direction;
    private float neckExtend;
    public float rotationValue;

    public GameObject joystick;
    public GameObject lever;
    public GameObject knob;
    public GameObject slider;
    public GameObject button;
    public GameObject head;
    public GameObject lightBulb;

    private float headBasePos;
    public float maxHeadAltitude;

    private Vector3 velocity = Vector3.zero;

    public Renderer rend;
    private Material matOne;
    public Material lightMat;

    // Use this for initialization
    void Start ()
    {
        headBasePos = head.transform.localPosition.y;
        //rend = GetComponent<Renderer>();
        
        matOne = rend.material;
    }
	
	// Update is called once per frame
	void Update ()
    {
        speed = slider.gameObject.GetComponent<VRSlider>().sliderValue;
        rotationValue = knob.gameObject.GetComponent<VRKnob>().KnobValue;
        neckExtend = lever.gameObject.GetComponent<VRLever>().leverValue;
        direction = new Vector2((joystick.GetComponent<VRJoystick>().joystickValueX - 0.5f) * 2, (joystick.GetComponent<VRJoystick>().joystickValueZ -0.5f) * 2);

        //transform.Translate((Vector3.forward * (speed) * Time.deltaTime) * direction.y);
        transform.position = new Vector3( ((speed * Time.deltaTime) * (direction.x * -1)) + transform.position.x, transform.position.y, ((speed * Time.deltaTime) * direction.y ) + transform.position.z);
        transform.eulerAngles = Vector3.SmoothDamp(transform.eulerAngles, new Vector3(0, (rotationValue * 360), 0), ref velocity, 0.4f);
        head.transform.localPosition = new Vector3(0, (headBasePos + (neckExtend * maxHeadAltitude)), 0);

        if (button.gameObject.GetComponent<VRButton>().buttonDown == true)
        {
            rend.GetComponent<Renderer>().material = lightMat;
        }
        else
        {
            rend.GetComponent<Renderer>().material = matOne;
        }
    }
}
