void Update() { timerAlive += Time.deltaTime; if (timerAlive >= 10) { Destroy(gameObject); } transform.Translate(Vector3.up * Time.deltaTime * 4, Space.Self); Ray ray = new Ray(transform.position - transform.up, transform.up); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1.2f, hitMask)) { GameObject go = Instantiate(audioPrefab); go.transform.position = transform.position; AudioSource source = go.GetComponent <AudioSource>(); bool remove = true; if (hit.collider.GetComponent <IAttackable>() != null) { IAttackable att = hit.collider.GetComponent <IAttackable>(); Debug.Log(hit.collider.name); att.Damage(1); source.clip = att.GetHitClip(); } else { source.clip = hitSound; } source.pitch = Random.Range(0.95f, 1.05f); source.volume = Random.Range(0.1f, 0.2f); if (remove) { source.Play(); Destroy(gameObject); } } }