Question by
younghaklee1995 · May 06 at 05:30 AM ·
collisioncollideranimator
How to enable specific event when other gameobject collides with the other prefab?
Hi, I'm making a saving hostage project. A hostage is being taken by the villain. If I shoot the villain, dying animation works because OnTriggerEnter is enabled. It works well but I don't know how to enable the released hostage animation.
If the villain collides with the bullet, the hostage's animator flow changes into "Any State -> Released animation." ( used bool event changes from false into true)
I made a tag of which name is "bullet" in the bullet prefab, and the code in the villain is like below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DyingScript : MonoBehaviour
{
[SerializeField]
private Animator animator;
private void Awake()
{
animator = GetComponent<Animator>();
animator.SetBool("isAttacked", false);
}
private void OnTriggerEnter(Collider other)
{
if(other.transform.tag == "Bullet")
{
Debug.Log("attacked");
animator.SetBool("isAttacked", true);
}
}
}
Comment