// Update is called once per frame void Update() { myTime = myTime + Time.deltaTime; Ray ray = this.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition); weapon.transform.LookAt(ray.direction * int.MaxValue); if (Input.GetButton("Fire1") && fireTimes < keepFire && myTime > nextFire) { fireTimes++; if (fireTimes >= keepFire) { nextFire = myTime + fireDelta; nextFire = nextFire - myTime; myTime = 0.0F; fireTimes = 0; } ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Physics.Raycast(ray, out hit); if (hit.collider != null) { IHitTarget target = hit.collider.GetComponentInParent <IHitTarget>(); if (target != null) { target.onHit(); } } playGunParticle(); } }
private static Color GetColor(Ray p_ray, IHitTarget p_world, int p_depth) { var maxDepth = 50; var hitRecord = new HitRecord(); if (p_world.WasHit(p_ray, 0.001, double.MaxValue, ref hitRecord)) { var scatteredRay = new Ray(new Vec3(0), new Vec3(0)); var attenuation = new Color(0, 0, 0); var emitted = hitRecord.Material.GetEmitted(hitRecord.U, hitRecord.V, hitRecord.Point); if (p_depth < maxDepth && hitRecord.Material.Scatter(p_ray, hitRecord, ref attenuation, ref scatteredRay)) { return(emitted + attenuation * GetColor(scatteredRay, p_world, p_depth + 1)); } return(emitted); } return(new Color(0, 0, 0)); //var unitDirection = Vec3.GetUnitVector(p_ray.Direction); //var t = 0.5 * (unitDirection.Y + 1.0); //return (1.0 - t) * new Color(1.0, 1.0, 1.0) + t * new Color(0.5, 0.7, 1.0); }
public void Explosion(Vector3 hitpos, float radius) { Collider[] hitcollider = Physics.OverlapSphere(hitpos, radius, -1); foreach (Collider enemy in hitcollider) { IHitTarget hitTarget = enemy.GetComponent <IHitTarget>(); if (hitTarget != null) { hitTarget.OnHit(); } } }
public virtual void HandleDamage(RaycastHit hit) { IHitTarget hitTarget = hit.collider.transform.root.gameObject.GetComponent <IHitTarget>(); HitData hitData; Vector3 knockback = transform.forward * knockbackForce + knockbackModifier; if (hitTarget != null) { hitData = new HitData(owner, damage, knockback, damageType, damageInflictionWhenDirectHit, hit.point); hitTarget.OnDamageHit(hitData); } if (useSplash) { if (IsDebug) { Debug.DrawLine(transform.position, transform.position + Vector3.up * bulletSplashRadius / 2, Color.blue, 10); Debug.DrawLine(transform.position, transform.position + Vector3.down * bulletSplashRadius / 2, Color.blue, 10); Debug.DrawLine(transform.position, transform.position + Vector3.left * bulletSplashRadius / 2, Color.blue, 10); Debug.DrawLine(transform.position, transform.position + Vector3.right * bulletSplashRadius / 2, Color.blue, 10); Debug.DrawLine(transform.position, transform.position + Vector3.forward * bulletSplashRadius / 2, Color.blue, 10); Debug.DrawLine(transform.position, transform.position + Vector3.back * bulletSplashRadius / 2, Color.blue, 10); } Collider[] hitObjects = Physics.OverlapSphere(transform.position, bulletSplashRadius, projectileHitLayers); foreach (Collider c in hitObjects) { IHitTarget explosionTarget = c.GetComponent <IHitTarget>(); if (explosionTarget != null) { float damageModifier = (useFalloffSplashDamage) ? 1 - (c.transform.position - transform.position).magnitude / bulletSplashRadius : 1; knockback = (c.transform.position - transform.position) * knockbackForce * damageModifier + knockbackModifier; hitData = new HitData(owner, damage * damageModifier, knockback, damageType, damageInflictionWhenSplash, hit.point); explosionTarget.OnDamageHit(hitData); if (IsDebug) { Debug.DrawLine(transform.position, c.transform.position, Color.red, 10); } } } } }