private void Hit() { float random_accu_min = -theCrosshair.GetAccuracy() - currentGun.accuracy; float random_accu_max = theCrosshair.GetAccuracy() + currentGun.accuracy; if (Physics.Raycast(theCam.transform.position, theCam.transform.forward + new Vector3(Random.Range(random_accu_min, random_accu_max), Random.Range(random_accu_min, random_accu_max), Random.Range(random_accu_min, random_accu_max)), out hitInfo, currentGun.range)) { GameObject clone = Instantiate(hit_effect_prefab, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); Destroy(clone, 2.0f); } }
private void Hit() { if (Physics.Raycast(theCam.transform.position, theCam.transform.forward + new Vector3(Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), 0) , out hitInfo, currentGun.range, layerMask)) { GameObject clone = Instantiate(hit_effect_prefab, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); Destroy(clone, 2f); } }
private void Hit() { if (Physics.Raycast(theCam.transform.position, theCam.transform.forward + //전방에 더함 new Vector3(Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), //상하좌우로 범위만큼 랜덤한 값을 Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), 0), out hitInfo, currentGun.range, layerMask))//이번엔 position -> local로하면 어느 위치에 있던 항상 같은 좌표 값을 주기 때문, layerMask 추가 { //hitino.point는 실제 좌표를 반환, LootRotation은 바라보는 방향, normal은 충돌한 곳의 표면을 반환함, 표면의 방향으로 나옴 GameObject clone = Instantiate(hit_effect_prefab, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); Destroy(clone, 2f);//프리펩이 계속 쌓이게 되어 삭제 } }
private void Hit() { if (Physics.Raycast(theCam.transform.position, theCam.transform.forward + new Vector3(Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), // random : min-max by accuracy Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), 0) , out hitInfo, currentGun.range)) { //point : coordinates ,normal : surface the ray hit GameObject clone = Instantiate(hit_effect_prefab, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); Destroy(clone, 2.0f); } }
// 쏘는 족족 맞게 하기 private void Hit() { // 충돌 검사 if (Physics.Raycast(theCam.transform.position, theCam.transform.forward + new Vector3(Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), 0) // 카메라 현재 위치에서 직진으로 쏘는데 랜덤을 더해서 쏜다 , out hitInfo, currentGun.range)) { // point -> 충돌한 곳의 실제 좌표를 반환, normal -> 충돌한 객체의 표면을 반환 // 반환되는 타입 모를 때 var 사용 가능 GameObject clone = Instantiate(hit_effect_prefab, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); Destroy(clone, 2f); } }
private bool HitCheck() { // 충돌한게 있다면 if (Physics.Raycast(transform.position, transform.forward + new Vector3(Random.Range(-theCrosshair.GetAccuracy() - theGun.accuracy, theCrosshair.GetAccuracy() + theGun.accuracy), Random.Range(-theCrosshair.GetAccuracy() - theGun.accuracy, theCrosshair.GetAccuracy() + theGun.accuracy), 0) , out hitInfo, theGun.attackRange)) { var clone = Instantiate(hit_effect, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); // 이펙트 표시 Destroy(clone, 2f); return(true); } return(false); }
private void Hit() { if (Physics.Raycast(theCam.transform.position, theCam.transform.forward + new Vector3(Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), Random.Range(-theCrosshair.GetAccuracy() - currentGun.accuracy, theCrosshair.GetAccuracy() + currentGun.accuracy), 0) //쏘는방향에 랜덤값(정확도에 영향을 받음)을 더해서 정확도를 좀더 사실적으로 구현 , out hitInfo, currentGun.range, layerMask)) { GameObject clone = Instantiate(hitEffectPrefab, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); //총알이맞은 바로 그지점에서 충돌한 개체의 노말(위)방향으로 생성 Destroy(clone, 2f); //생성된 이펙트를 2초후 제거하여 메모리 확보 //동물일경우 if (hitInfo.transform.tag == "NPC") { //동물에게 일정데미지 입힘 //hitInfo.transform.GetComponent<Rhino>().Damage(currentCloseWeapon.damage,transform.position); //도끼의 데미지와 도끼의 현재위치를 넘겨줌 SoundManager.instance.PlaySE("Animal_Hit"); hitInfo.transform.GetComponent <Rhino>().Damage(1, transform.position); //실험용 데미지1 } } }