I have script (down bellow) that activates a bell then plays it animation, audio once, and use use a ray cast
the problem is the sound wont play (no errors)
the animation plays but gets 2 warring (Animator.GotoState: State could not be found) (invalid layer index -1)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ringbell : MonoBehaviour
{
public float range = 100f;
public bool IsRing = false;
public GameObject bell;
public GameObject Ghost;
public AudioSource bellsring;
public Camera fpsCam;
private Animator animator;
void Update()
{
if (Input.GetMouseButton(0))
{
if ((IsRing == false))
{
StartCoroutine(ringthebell());
}
}
}
IEnumerator ringthebell()
{
bell.SetActive(true);
IsRing = true;
bell.GetComponent<Animator>().Play("ringbell");
yield return new WaitForSeconds(1f);
bell.GetComponent<Animator>().Play("none");
IsRing = false;
bell.SetActive(false);
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Dissapper dissapper = hit.transform.GetComponent<Dissapper>();
if (dissapper != null)
{
dissapper.Gone();
}
if ((Ghost == true))
{
EndGame endgame = hit.transform.GetComponent<EndGame>();
if (endgame != null)
{
endgame.Die();
}
}
}
}
}