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;
}
}