Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Implementing video array in unity

// This script won't work without a VideoPlayer present,
// so let's ask Unity to enforce that relationship for us.
[RequireComponent(typeof(VideoPlayer))]

// The C# convention for class names is PascalCase.
public class VideoManager : MonoBehaviour {

    // Don't create/size the Array in Start() - that makes an empty
    // array, discarding the clips you assigned in the Inspector.
    public VideoClip[] vids = new VideoClip[26];

    private VideoPlayer vp;

    void Start () {
        vp = gameObject.GetComponent<VideoPlayer> ();
    }

    // Call this method when it's time to play a particular video.
    // Pass a number from 0 to 25 inclusive to choose which video.
    public PlayVideo(int id) {
        // To be safe, let's bounds-check the ID 
        // and throw a descriptive error to catch bugs.
        if(id < 0 || id >= vids.Length) {
            Debug.LogErrorFormat(
               "Cannot play video #{0}. The array contains {1} video(s)",
                                   id,                 vids.Length);
            return;
        }

        // If we get here, we know the ID is safe.
        // So we assign the (id+1)th entry of the vids array as our clip.
        vp.clip = vids[id];

        vp.Play();
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: f# get last element of list 
Csharp :: C# date type no time 
Csharp :: calculate string length vs pixels c# 
Csharp :: Entity framwork update parent entity added new sub entity 
Csharp :: concurrent post request c# 
Csharp :: c# generate insert statement from object 
Csharp :: read system data dataset 
Csharp :: mongodb custom IIdGenerator 
Csharp :: Delayed respawn timer 
Csharp :: c# bool? to bool 
Csharp :: c# check multiple variables for null 
Csharp :: no cameras rendering unity 
Csharp :: c# winform get access token facebook 
Csharp :: infinit range loop c# 
Csharp :: windows forms change double buffer during runtime 
Csharp :: how to refresh the data table in C# window form datagridview 
Csharp :: how to get angular on visual studio mac 
Csharp :: loop code for X seconds 
Csharp :: in c# show error when user choose old datetime 
Csharp :: negative indexing in c# 
Csharp :: enumerate dictionary c# 
Csharp :: how to show enum name list from input in swagger c# 
Csharp :: f# print array strings 
Csharp :: c# linq query map to entity 
Csharp :: binary search between two indexes 
Csharp :: 1180 - Lowest Number and Position C# 
Csharp :: unrecognized escape sequence c# connection string 
Csharp :: scroll two divs simultaneously site:stackoverflow.com 
Csharp :: winforms reportviewer.print report 
Csharp :: wpf change the content of the button wait 5 secound and then change it again 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =