Hi, I ran into an issue about a week ago. When I opened Unity, it said that there were issues with my script and that I should open Unity in safe mode. This was odd because there were no issues when I left Unity, like they had been created in between closing Unity and Opening it again. I opened it in safe mode, and found that the issue was that all of the functions to do with the video player component (stop, clip, play) weren’t registering, and they have a red line under them in visual studio. These functions were fine before but suddenly weren’t working.
I tried updating Unity which solved the issue once, but after closing and opening it again, the same issue occurred. My visual studio is updated to the latest version.
Any ideas? I don’t think it’s an issue with my code, but an issue with how visual studio or unity is reading my code (but obviously I could be wrong.)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class VideoPlaying : MonoBehaviour
{
private VideoPlayer videoPlayer;
public VideoClip[] videoClips;
static VideoSelector videoSelectorScript;
//0 = Blue, 1 = Red, 2 = Party, 3 = Purple, 4 = Orange
int valueOfParty;
int personTalking;
Vector3 startPosition;
Vector3 startScale;
private void Awake()
{
videoPlayer = GetComponent<VideoPlayer>();
videoSelectorScript = GetComponentInParent<VideoSelector>();
}
void Start()
{
startPosition = transform.localPosition;
startScale = transform.localScale;
switch (gameObject.name)
{
case "VideoPlayerBlue":
valueOfParty = 0;
break;
case "VideoPlayerRed":
valueOfParty = 1;
break;
case "VideoPlayerParty":
valueOfParty = 2;
break;
case "VideoPlayerPurple":
valueOfParty = 3;
break;
case "VideoPlayerOrange":
valueOfParty = 4;
break;
}
}
//Every time a prompt is accepted, each of these ints is used to determine the video to play
//and the transform of the object
//Party recieving is the literally just which party has this class attached to it
//firstpersonspeaking and secondpersonspeaking starts at one and ends at 5, with 0 representing nothing.
public void ClipUpdate(int numberOfPeopleSpeaking, int firstPersonSpeaking, int secondPersonSpeaking, int firstClipNumber, int secondClipNumber)
{
switch (numberOfPeopleSpeaking)
{
case 0:
//Stationary
gameObject.SetActive(true);
transform.localPosition = startPosition;
transform.localScale = startScale;
videoPlayer.clip = videoClips[0];
videoPlayer.Play();
break;
case 1:
//If you are the one talking
if (firstPersonSpeaking == valueOfParty + 1)
{
gameObject.SetActive(true);
videoPlayer.clip = videoClips[firstClipNumber];
videoPlayer.Play();
transform.localPosition = Vector3.zero;
transform.localScale = new Vector3(8, 6, 1);
Invoke("VideoOver", (float)videoClips[firstClipNumber].length);
}
else
{
videoPlayer.Stop();
gameObject.SetActive(false);
}
break;
case 2:
if (firstPersonSpeaking == valueOfParty + 1)
{
transform.localPosition = new Vector3(-2.75f, 0, 0);
transform.localScale = new Vector3(5.4f, 4.05f, 1);
videoPlayer.clip = videoClips[firstClipNumber];
videoPlayer.Play();
gameObject.SetActive(true);
}
else if (secondPersonSpeaking == valueOfParty + 1)
{
transform.localPosition = new Vector3(2.75f, 0, 0);
transform.localScale = new Vector3(5.4f, 4.05f, 1);
videoPlayer.clip = videoClips[secondClipNumber];
videoPlayer.Play();
gameObject.SetActive(true);
Invoke("VideoOver", (float)videoClips[secondClipNumber].length);
}
else
{
videoPlayer.Stop();
gameObject.SetActive(false);
}
break;
default:
break;
}
}
void VideoOver()
{
videoSelectorScript.ContactPlayingScript(0, 0, 0, 0, 0);
videoSelectorScript.Invoke("VideoEnd", 0.5f);
}
}
Sorry for the long script. The important thing is that videoPlayer.Stop, videoPlayer.Play and videoPlayer.clip are all underlined in red.