horror game script ring and bell and the ghost disappears temporally

Trying to make a script that when you ring the bell the ghost disappears for a certain amount of time then reappear

I know how to yield return new WaitForSeconds and triggering another script but not sure how to combined them, this what I came up with but not sure what is exactly wrong
us
``uing System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ringbell : MonoBehaviour
{
    public bool IsRing = false;
    public bool Death = false;
    public GameObject bell;
    public AudioSource bellsring;
    public GameObject Ghost;

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            if ((IsRing == false))
            {
                StartCoroutine(ringthebell());
            }
        }
    }

    IEnumerator ringthebell()
    {
        bell.SetActive(true);
        IsRing = true;
        bell.GetComponent<Animator>().Play("ringbell");
        bellsring.Play();
        yield return new WaitForSeconds(1f);
        bell.GetComponent<Animator>().Play("none");
        IsRing = false;
        bell.SetActive(false);

        disappear Disappear = ringthebell.transform.GetComponent<disappear>();
        if (target != null)
        {
            Disappear.bellrung();
        }
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Animations;

public class disappear : MonoBehaviour
{
    public GameObject Ghost;
    public Animator controller;

    public void bellrung()
    {
        StartCoroutine(bellrung());
    }

    IEnumerator bellrung()
    {
        controller.SetBool("Death", true);
        yield return new WaitForSeconds(0.05f);
        Ghost = false;
        yield return new WaitForSeconds(5f);
        Ghost = true;
    }
}

@jackmw94
That helped, also I talk to a friend that toke coding back in college and said I was missing a trigger for the ringbell script to the disappear script, I need like a raycast hit or something to that effect, but I’m not sure how to do it, cause I want it to be a area of effect thing, any suggestions

What does Ghost = false do? Ghost is the GameObject you want to hide I guess. Then use Ghost.SetActive(false)


Btw I really really recommend to use some consistent naming for variables, methods and classes. It makes the code much easier to read. Google some naming convention (idealy C#) and look at it. For class names is usually used PascalCase and for variable names camelCase. I personally use uderscore for class variable names like this: _variable. The main point is that is has to be consistent.

When you say you’re not sure what is wrong, what is happening?

I can see from your code you’ll have a compiler error in bellrung in your disappear class. Your variable Ghost is a GameObject but you’re assigning a bool value to it (true/false). Also in ringthebell in your Ringbell class you have an undefined variable called target.

If you want to set the ghost inactive then you can call SetActive(false) like you do with the bell GameObject. I am not sure what target should be or whether you need it.

If this doesn’t solve your problem then let me know what you expect to happen compared to what is actually happening :slight_smile: