Creating a point clicking cutscene system (713396)

Hi everyone
I created a cutscene point, if the player gets into it’s collider2D then then cutscene will be played, I’m writing a script which shows bunch of buttons in order in the cutscene, (if the player clicks on the buttons on time then the next button will be shown, if doesn’t click on time then the “lose” animation will be played). I wrote this code but the else conditions never run! even if the state value is zero!
here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class newact : MonoBehaviour {
public Animator _playeranim;
  public Animator _CameraAnim;
  public GameObject Btn1;
  public GameObject Btn2;
  public GameObject Btn3;

  public int state;
  void Start () {
    

  }

  public IEnumerator CutScene1(){
    yield return new WaitForSeconds (1.5f);
    _CameraAnim.Play ("Cutscene-2");
    yield return new WaitForSeconds (0.5f);
    Btn1.SetActive (true);






  }
  public IEnumerator CutScene2(){

    if (state == 1) {
      Btn1.SetActive (false);
      Btn2.SetActive (true);
      yield return new WaitForSeconds (1.5f);

    } else {
      StartCoroutine ("lose");
    }
  }

  public IEnumerator CutScene3(){

    if (state == 1) {
      Btn2.SetActive (false);
      Btn3.SetActive (true);
      yield return new WaitForSeconds (1.5f);

    } else {
      StartCoroutine ("lose");
    }
  }

  public IEnumerator end(){

    if (state == 1) {
      Btn3.SetActive (false);
      yield return new WaitForSeconds (1.5f);

          }
    else {
      StartCoroutine ("lose");
    }
  }

  public IEnumerator lose(){
 
    _playeranim.Play ("sleep");
    Btn1.SetActive (false);
    yield return new WaitForSeconds (1.5f);

 
 
  }


  void OnTriggerEnter2D(Collider2D other){
    if (other.tag == "Player") {
      StartCoroutine ("CutScene1");
    }
  }
public void btn1_click(){
 
    state = 1;
    StartCoroutine ("CutScene2");

 
  }
public void btn2_click(){
 
    state = 1;
    StartCoroutine ("CutScene3");
 
  }
public void btn3_click (){
 
    state = 1;
    StartCoroutine ("end");
 
  }
}

You’re going to have to either use the debugger and some breakpoints, or else put some Debug.Log() statements (with unique strings outputted) in various parts of your program to find out what is actually happening.

1 Like

Hi m146979, you have already created exactly this same thread earlier .

So now that Kurt-Dekker has also given you exactly the same advise that I did, will you follow it rather than re-posting the same thread again please? If you need help with debugging, then do feel free to ask. :slight_smile:

1 Like