Search Unity

How to make an interactive cutscene?

Discussion in 'Scripting' started by m146979, Sep 12, 2018.

  1. m146979

    m146979

    Joined:
    Feb 14, 2018
    Posts:
    5
    Hi I wanna create an interactive cutscene ,(games like God of War or some of the newer Tomb Raider games, where you will enter an area, and a cutscene of sorts will begin, and you must press a button at a certain time in order to dodge an obstacle, land an attack on an enemy, etc. u have to press the button in time, or pressing the wrong button, will result in the player taking damage, or (in the case of the Tomb Raider games) dying )
    yeah I wanna create something like this but I don't know how to write the script, by the way I have this script:


    Code (CSharp):
    1. public GUISkin GUI_Skin;
    2. public float FirstReponseWait = 5.0f;
    3. //Time to wait after start until the first reponse is requested
    4. public float SecondResponseWait = 5.0f;
    5. //Time to wait after the first reponse until the second response is requested
    6. private bool CanAction1= false;
    7. private bool CanAction2= false;
    8. private bool CanAction3= false;
    9.  
    10.  
    11. void  Start (){
    12.     yield return new WaitForSeconds(FirstReponseWait);
    13.     CanAction1 = true;
    14. }
    15.  
    16. void  Update (){
    17.     //If player press Action key, play the next camera animation
    18.     if(CanAction1)
    19.     {
    20.         FirstReponse();
    21.     }
    22.    
    23.     //If player press Action key, play the next camera animation
    24.     if(CanAction2  && Input.GetKeyDown("e"))
    25.     {
    26.         SecondReponse();
    27.         CanAction2 = false;
    28.     }
    29. }
    30.  
    31.  
    32. void  FirstReponse (){
    33.     if(Input.GetKeyDown("e"))
    34.     {
    35.         ActionOne();
    36.         this.gameObject.animation.CrossFadeQueued("Animation2", 1, QueueMode.PlayNow);
    37.     }
    38. }
    39.  
    40. void  OnGUI (){
    41.     //Set the text style for screen prompt
    42.     GUI.skin = GUI_Skin;
    43.    
    44.     //If game is waiting for response 1, show screen prompt
    45.     if(CanAction1)
    46.     {
    47.         GUI.Label( new Rect((Screen.width / 2) - (19 / 2), Screen.height / 2, 500 , 100), "Press 'E' for Action 1");
    48.     }
    49.    
    50.     //If game is waiting for response 2, show screen prompt
    51.     if(CanAction2)
    52.     {
    53.         GUI.Label( new Rect((Screen.width / 2) - (19 / 2), Screen.height / 2, 500 , 100), "Press 'E' for Action 2");
    54.     }
    55. }
    56.  
    57. void  ActionOne (){
    58.     CanAction1 = false;
    59.     yield return new WaitForSeconds(SecondResponseWait);
    60.     CanAction2 = true;
    61. }
    62.  
    63. void  SecondReponse (){
    64.     this.gameObject.animation.CrossFadeQueued("Animation3", 1, QueueMode.PlayNow);
    65. }
    66. }
    but I wanna do this with ui buttons and I wanna add a time limit for clicking on buttons plus a fail condition containing the death animation.

    please help!
     
  2. StickyHoneybuns

    StickyHoneybuns

    Joined:
    Jan 16, 2018
    Posts:
    207
    Doing a cutscene is really no different then the rest of the game. However in the cutscene the director(you) have more control over whats happening and in a sense can be easier since the player is severly limited on what they can do. Since you say "I have this script" does that mean you didn't write it and are not very good at writing scripts? If so, you need to do the Unity tutorials first.

    https://unity3d.com/learn/tutorials

    Even if you do know how to program I would still do the tutorials. They are extremely helpful.

    Here is UI buttons:
    https://docs.unity3d.com/ScriptReference/UI.Button.html

    What you will need for this to work is control over the player. Disable their input except when you need them to click. This is as siimple as adding a boolean value in the player input script. Have UI buttons pop up when you want them. The most involved will be directing the scene to do what you want to, i.e. animating the various characters and objects. If this is 3rd person view then you will probably have multiple camera angles for a cinematic type look. That is as simple as moving the camera at a specified time.