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

public class vidcontrol1 : MonoBehaviour
{
    [SerializeField] float starttime;

    VideoPlayer vplayer;
    float playtime;
    bool isplaying = false;

    Renderer rend;
    float alpha;

    private void Awake()
    {
        vplayer = GetComponent<VideoPlayer>();
        rend = GetComponent<Renderer>();
    }

    // Start is called before the first frame update
    void Start()
    {
        playtime = Time.time + starttime;
        alpha = 0.0f;
        rend.material.color = new Color(1.0f, 1.0f, 1.0f, alpha);
    }

    // Update is called once per frame
    void Update()
    {
        if (Time.time > playtime && !isplaying) {
            vplayer.Play();
            isplaying = true;
        }
        if (isplaying) {
            alpha = Mathf.PingPong((Time.time - 5.0f) * 0.2f, 1.0f);
            rend.material.color = new Color(1.0f, 1.0f, 1.0f, alpha);
        }
    }
}
