using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyHitted : MonoBehaviour { Animator m_Animator; public AudioClip HitSound; private AudioSource audioSource; // Use this for initialization void Start () { audioSource = GetComponent(); m_Animator = gameObject.GetComponent(); } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { Debug.Log(hit.transform.tag.ToString()); if (hit.transform.tag == "Enemy") { audioSource.PlayOneShot(HitSound); // Destroy(hit.transform.gameObject); m_Animator.SetBool("bLive", false); } } } } public void ObjectDestroy() { Destroy(this.gameObject); } }