Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question My script stop working.

Discussion in 'Getting Started' started by HallowBoi, Mar 5, 2024.

  1. HallowBoi

    HallowBoi

    Joined:
    Aug 15, 2022
    Posts:
    2
    Hello everyone. Im new to the game development and also new to the unity and scripting. Currently im working on a small project to learn about unity, scripting etc... My problem is that i have a script attached to a invisible trigger wall. İt starts a cutscene when player touch the wall. and activate and deactive some other objects. Script works perfectly until today. The problem is rakıYokOl game object dont disable after cutscene starts. and doguZıbar dont get active after cutscene starts. Am i missing something.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Video;
    5.  
    6. public class abduScript : MonoBehaviour
    7. {
    8.     public GameObject cutsceneObject;
    9.     public GameObject doguZıbar;
    10.     public GameObject rakıYokOl;
    11.     public GameObject trigger3;
    12.     public Animator cutsceneAnim;
    13.     public bool preRendered;
    14.     public VideoPlayer preRenderedVideo;
    15.     public string cutsceneTriggerName;
    16.     public SC_FPSController playerScript; //Replace 'SC_FPSController' with your player script's name
    17.     public Camera playerCam;
    18.     public float cutsceneTime;
    19.     public footsteps footstepsScript;
    20.     void OnTriggerEnter(Collider other)
    21.     {
    22.         if (other.CompareTag("Player"))
    23.         {
    24.             footstepsScript.SetCutscenePlaying(true);
    25.             playerScript.enabled = false;
    26.             rakıYokOl.SetActive(false);
    27.             doguZıbar.SetActive(true);
    28.             trigger3.SetActive(true);
    29.  
    30.             if (preRendered == false)
    31.             {
    32.  
    33.                 cutsceneObject.SetActive(true);
    34.                 playerCam.enabled = false;
    35.                 cutsceneAnim.SetTrigger(cutsceneTriggerName);
    36.                 StartCoroutine(cutsceneRoutine());
    37.             }
    38.             if (preRendered == true)
    39.             {
    40.                 cutsceneObject.SetActive(true);
    41.                 StartCoroutine(cutsceneRoutine());
    42.                 preRenderedVideo.Play();
    43.             }
    44.             this.gameObject.GetComponent<BoxCollider>().enabled = false;
    45.         }
    46.     }
    47.     IEnumerator cutsceneRoutine()
    48.     {
    49.         yield return new WaitForSeconds(cutsceneTime);
    50.         playerScript.enabled = true;
    51.         playerCam.enabled = true;
    52.         cutsceneAnim.enabled = false;
    53.         cutsceneObject.SetActive(false);
    54.         footstepsScript.SetCutscenePlaying(false);
    55.         if (preRendered == true)
    56.         {
    57.             preRenderedVideo.Stop();
    58.             cutsceneObject.SetActive(false);
    59.         }
    60.     }
    61.  
    62. }
    63.  
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,132
    Any erorrs?
    Did you already check if the references are correct and not prefabs?

    Does the code go through the correct if statement?
     
  3. HallowBoi

    HallowBoi

    Joined:
    Aug 15, 2022
    Posts:
    2
    There are no errors in the console. I think rakıYokOl object is prefab because it has blue color at the hierarchy. But its also prefab while the script was working.