0

as i am new to unity i am having difficulty with timelining, i created an empty object using that i created a camera and placed it in timeline cinemachine used a few objects and VM camears and created a trailer, now i want that animation to play when player enters a trigger, my game is a 3d game with 2 cameras first person and third person camera to when i start my game with that timeline object active it starts to play but all i can hear it voices as my main camera is on player! anybody who can help me with how to use timeline on trigger? that would be of great help.

1 Answers1

0

You could achieve that by multiple ways one of them would be:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;

public class TimelineController : MonoBehaviour {

    public List<PlayableDirector> playableDirectors;
    public List<TimelineAsset> timelines;


    public void Play()
    {
        foreach (PlayableDirector playableDirector in playableDirectors) 
        {
            playableDirector.Play ();
        }
    }

    public void PlayFromTimelines(int index)
    {
        TimelineAsset selectedAsset;

        if (timelines.Count <= index) 
        {
            selectedAsset = timelines [timelines.Count - 1];
        } 
        else 
        {
            selectedAsset = timelines [index];
        }

        playableDirectors [0].Play (selectedAsset);
    }
}

For further details see this video https://www.youtube.com/watch?v=cmExSYI2yd0&feature=youtu.be

For more detailed about how timeline works you can visit:

https://learn.unity.com/tutorial/timeline?signup=true

Syed Munim Raza
  • 195
  • 2
  • 11
  • i have used VM cameras for timeline so when on trigger that timeline starts playing it doesnot deactive player camera so all i can hear is voices playing, how can i switch between that? – warda baig Oct 05 '19 at 09:19
  • @wardabaig I am assuming you are calling MainCamera the player camera and when you have virtual cameras in your scene then you don't actually have to deactivate the main camera you just activate virtual camera and the main camera will follow the transform of virtual camera and will see what ever virtual camera has supposed to see. – Syed Munim Raza Oct 05 '19 at 21:32
  • So let's break this down. 1. You have main camera with cinemachine brain component attached with it. 2. You created multiple virtual cameras (turn off initially). 3. Now you have to play the cutscene and you turns on the one virtual camera. 4. Main Camera will change its transform towards virtual camera by default it will tween towards that position. – Syed Munim Raza Oct 05 '19 at 21:32
  • One more thing that could be the issue is that "Main Camera" tag would be one 1 camera and you are seeing from the other camera which is actually not moving and cinemachine has moved that main camera but actually you have another camera 2 also so for this you will have to turn off that 2nd camera for whatever reason you have 2 cameras turn the camera which doesn't has cinemachine brain component with itself. – Syed Munim Raza Oct 05 '19 at 21:36
  • 1.main camera on player. 2. another view cam which has cinemachine brain on it with 4 virtual cameras, when player enter the room i want player camera to be deactivated and activate view camera along with vm cameras which, and after the timeline plays come back to the main camera. problem that i am facing is when i deactivate my player camera it doesn't do so, and starts playing timeline as i can hear it but cannot see the cutscene. – warda baig Oct 06 '19 at 10:13
  • @wardabaig Just test case: In inspector turn off the player focusing camera. Now you will have only other camera left(for cutscene). What do you see? Also if you could share some screenshots that would be great. – Syed Munim Raza Oct 06 '19 at 11:48
  • when i turn off player camera cutscene camera appears. please if you could help as i'm short of time i need to show my work by tomorrow. – warda baig Oct 06 '19 at 13:37
  • @wardabaig sorry for the delay. If all you need is to turn off player camera and rest of things are working in place then you could use OnTriggerEnter method and when player enter the room turn off the main camera and start the cutscene. – Syed Munim Raza Oct 07 '19 at 14:43
  • @SyedMunimRazai got the solution it was on timeline creation that i had to set my cutscene camera active on time of display and then turn it off onTriggerExit – warda baig Oct 11 '19 at 10:44
  • @wardabaig glad you figured it out. btw last comment was onTriggerEnter and Exit. Anyhow best of luck for future adventures. – Syed Munim Raza Oct 13 '19 at 13:13