void fire() { RaycastHit hit; if (Physics.Raycast(udder.transform.position, udder.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); target enemy = hit.transform.GetComponent <target> (); if (enemy != null) { enemy.damage(damage); } } }
void shoot() { AudioSource source = GetComponent <AudioSource>(); source.clip = clip; muzzleflash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); target t = hit.transform.GetComponent <target>(); if (t != null) { source.Play(); // source.Stop(); GameObject hObject = Instantiate(hiteffect, hit.point, Quaternion.LookRotation(hit.normal)); t.damage(damage); Destroy(hObject, 2f); } else { source.Play(); // source.Stop(); GameObject gObject = Instantiate(groundhit, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(gObject, 2f); } } }