void Shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(FpsCam.transform.position, FpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); if (hit.transform.name == "cible(Clone)") { GameObject.Find("cible(Clone)").GetComponent <cibleBehavior>().gethit = true; } target Target = hit.transform.GetComponent <target>(); if (Target != null) { Target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } } }
void Update() { if (isDestinationReached()) { Destroy(gameObject); return; } transform.Translate(Vector3.forward * speed * Time.deltaTime); if (destination != Vector3.zero) { return; } RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 5f)) { CheckDistructable(hit); target target = hit.transform.GetComponent <target>(); if (target != null) { target.TakeDamage(damage); } } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactforces); } }
void shoot() { //var newbullet = Instantiate(bulletPrefab, (transform.position + transform.up * 1.5f + transform.forward), Quaternion.identity); // Destroy(newbullet, 2f); shaker.Triggershake(); muzzleFlash.Play(); currentAmmo--; ammo--; RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); target target = hit.transform.GetComponent <target>(); if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 2f); } }
void shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); target target = hit.transform.GetComponent <target> (); if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 2f); } }
void Update() { if (Input.GetKeyDown(KeyCode.Space) && Time.time > nextFire && !is_fire) { is_fire = true; anim.Play("recul"); audio_fire.enabled = false; first_collider.GetComponent <BoxCollider>().enabled = false; nextFire = Time.time + fireRate; StartCoroutine(ShotEffect()); Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); RaycastHit hit; laserLine.SetPosition(0, gunEnd.position); if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange)) { laserLine.SetPosition(1, hit.point); target Target = hit.transform.GetComponent <target>(); BoxCollider Target_collider = hit.transform.GetComponent <BoxCollider>(); if (Target != null && !Target_collider.isTrigger) { Target.TakeDamage(gunDamage); GameObject impact = Instantiate(ImpactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impact, 0.5f); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * hitForce); } else { laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange)); } } first_collider.GetComponent <BoxCollider>().enabled = true; } if (is_fire) { is_fire_time += Time.deltaTime; if (is_fire_time > anim.clip.length) { is_fire = false; is_fire_time = 0; } } }
private void OnTriggerEnter(Collider other) { target tar = other.GetComponent <target>(); if (tar != null) { tar.TakeDamage(damage); } Destroy(gameObject); }
void Shoot() { LayerMask mask = LayerMask.GetMask("Terrain", "Enemy"); RaycastHit2D hit = Physics2D.Raycast(fireStart.position, fireStart.up, range, mask); if (hit.collider != null) { target gametarget = hit.transform.GetComponent <target>(); if (gametarget != null) { gametarget.TakeDamage(damage); } } }
void shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); target target = hit.transform.GetComponent <target>(); if (transform != null) { target.TakeDamage(damage); } } }
void Shoot() { muzzleFLash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { target target = hit.transform.GetComponent <target>(); if (target != null) { target.TakeDamage(damage); } GameObject impactGo = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGo, 2f); } }
// Update is called once per frame void Update() { if (Input.GetButton("Fire1")) { Shoot(); } void Shoot() { RaycastHit hit; if (Physics.Raycast(fpscam.transform.position, fpscam.transform.forward, out hit, range)) { target target = hit.transform.GetComponent <target>(); if (target != null) { target.TakeDamage(damage); } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { shoot(); } void shoot() { shot.Play(); RaycastHit hit; if (Physics.Raycast(camera.position, camera.forward, out hit, maxDistance)) { target t = hit.transform.GetComponent <target>(); if (t != null) { t.TakeDamage(10f); } } } }
void Shoot() { myAnim.SetTrigger("recoil"); muzzleflash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { ; } { Debug.Log(hit.transform.name); target target = hit.transform.GetComponent <target>(); if (target != null) { target.TakeDamage(damage); } Ray ray = new Ray(transform.position, transform.forward); line.SetPosition(0, ray.origin); line.SetPosition(1, ray.GetPoint(100)); } }
void shoot() { p.Play(); RaycastHit hit; if (Physics.Raycast(fps.transform.position, fps.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); target t = hit.transform.GetComponent <target>(); if (t != null) { t.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddExplosionForce(5f, hit.point, 1f); } } GameObject eff = Instantiate(impacteff, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(eff, 2f); }
private void Shoot() { shot.Play(); RaycastHit hitInfo; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hitInfo, distance)) { Debug.Log(hitInfo.transform.name); target tar = hitInfo.transform.GetComponent <target>(); if (tar != null) { tar.TakeDamage(damage); } if (hitInfo.rigidbody != null) { hitInfo.rigidbody.AddForce(-hitInfo.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hitInfo.point, Quaternion.LookRotation(hitInfo.normal)); Destroy(impactGO, 2f); } }