Hi guys,
Battling a little here. Trying to make a TV that can play videos and allow the user to change channels. Its working, but the problem is that the video starts from the beginning again after you change the channel.
So I dont really know how to handle this. Should the video keep playing from the start with volume turned down and then activated, or is there a way to resume the video from the last point. Any help would be appreciated.
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class TVRemoteControl : MonoBehaviour
{
public PlayerTankControls ptc;
public GameObject tvRemote;
public MeshRenderer tvScreen;
public bool tvIsOn = false;
private VideoPlayer nextChannel;
public VideoPlayer [] videoPlayers;
private int videoPlayerIndex;
private void Update()
{
print(videoPlayerIndex);
CheckIfSitting();
ChangeChannel();
}
void CheckIfSitting()
{
if (ptc.sittingOnHouseCouch == true)
{
tvRemote.SetActive(true);
} else
{
tvRemote.SetActive(false);
}
}
public void TurnTvOn()
{
tvIsOn = true;
tvScreen.enabled = true;
}
public void TurnTvOff()
{
tvIsOn = false;
tvScreen.enabled = false;
}
public void ChannelUp()
{
if (tvIsOn)
{
videoPlayerIndex++;
if (videoPlayerIndex > 3)
{
videoPlayerIndex = 3;
}
if (videoPlayerIndex >= videoPlayers.Length)
{
videoPlayerIndex = videoPlayerIndex % videoPlayers.Length;
}
}
}
public void ChannelDown()
{
if (tvIsOn)
{
videoPlayerIndex--;
if (videoPlayerIndex <= 0)
{
videoPlayerIndex = 0;
}
if (videoPlayerIndex >= videoPlayers.Length)
{
videoPlayerIndex = videoPlayerIndex % videoPlayers.Length;
}
}
}
private void ChangeChannel()
{
nextChannel = videoPlayers[videoPlayerIndex];
nextChannel.enabled = true;
}
}
Might be better asked in Audio/Video?
Up to you, let me know if you agree and want me to move your post there.
What ever you feel is best MelvMay, i dont mind.