Exemple #1
0
    private void OnTriggerEnter(Collider other)
    {
        Collider[] hits = Physics.OverlapSphere(this.transform.position, explosionRadius);
        foreach (Collider hit in hits)
        {
            if (Vector3.Distance(this.transform.position, hit.transform.position) < coreRadius)
            {
                IHealth damageable = hit.GetComponent <IHealth>();

                if (damageable != null)
                {
                    if (EventManager.OnDamagedSomething != null)
                    {
                        EventManager.OnDamagedSomething(transform.name, hit.gameObject.name, damageType, damage);
                    }
                    damageable.Damage(bulletSource, damageType, damage);
                }
            }
            else
            {
                IHealth damageable = hit.GetComponent <IHealth>();

                if (damageable != null)
                {
                    if (EventManager.OnDamagedSomething != null)
                    {
                        EventManager.OnDamagedSomething(transform.name, hit.gameObject.name, damageType, splashDamage);
                    }
                    damageable.Damage(bulletSource, damageType, splashDamage);
                }
            }
        }

        Destroy(this.gameObject);
    }
Exemple #2
0
    public override void Shoot()
    {
        if (cooldownTimer >= cooldown)
        {
            cooldownTimer = 0f;
            Ray        ray = new Ray(emitTransform.position, emitTransform.forward);
            RaycastHit hit;
            Debug.DrawRay(emitTransform.position, emitTransform.forward, Color.red, 1f);

            GameObject   newLine = Instantiate(hitscanLine);
            LineRenderer line    = newLine.GetComponent <LineRenderer>();
            line.SetPosition(0, emitTransform.position);
            line.SetPosition(1, emitTransform.TransformPoint(emitTransform.localPosition + new Vector3(0f, 0f, 300f)));

            if (Physics.Raycast(ray, out hit))
            {
                IHealth damageable = hit.collider.gameObject.GetComponent <IHealth>();

                if (damageable != null)
                {
                    int damage = UnityEngine.Random.Range(minDamage, maxDamage + 1);

                    // Debug.Log(damage);
                    damageable.Damage(transform.root.gameObject, damageType, damage);

                    if (EventManager.OnDamagedSomething != null)
                    {
                        EventManager.OnDamagedSomething(transform.root.name, hit.collider.transform.root.name, damageType, damage);
                    }
                }
            }
        }
    }
Exemple #3
0
    protected virtual void FireOnce()
    {
        Vector3 start = userCommunicator.LookStartPos();
        Vector3 end;

        bool hitHealthComponent = false;

        Vector3 direction = Quaternion.Euler(InaccuracyOffset()) * userCommunicator.LookDirection();

        RaycastHit hitInfo;

        if (Physics.Raycast(start, direction, out hitInfo, range, layermask))   //Hits something
        {
            end = hitInfo.point;
            IHealth health = hitInfo.collider.GetComponent <IHealth>();
            Debug.Log(hitInfo.collider);
            if (health != null)
            {
                hitHealthComponent = true;
                health.Damage(damage);
            }
        }
        else
        {
            end = NagaUtils.GetPointAlongDirection(start, direction, range);
        }

        Debug.DrawLine(start, end, Color.white, 0.4f);

        onHitscanShoot.Invoke((new ShootInfo[] { new ShootInfo(start, end, hitInfo, hitHealthComponent) }));
    }
Exemple #4
0
 void TryDamage(IHealth health, float deltaTime)
 {
     if (health != null)
     {
         float      damageAmount = damagePerSecond * deltaTime;
         DamageInfo damageInfo   = new DamageInfo(this, damageAmount, damageType);
         health.Damage(damageInfo);
     }
 }
Exemple #5
0
 void Update()
 {
     if (Input.GetKeyUp("a") && PlayerHealth.CurrentHP > 0)
     {
         // Stop the previous lerp. Update the health and start a new lerp.
         StopCoroutine("LerpHealth");
         PlayerHealth.Damage(5);
         StartCoroutine("LerpHealth");
     }
 }
Exemple #6
0
    private void OnCollisionEnter(Collision collision)
    {
        IHealth otherCompHealth = (IHealth)collision.gameObject.GetComponent(typeof(IHealth));

        if (otherCompHealth != null)
        {
            otherCompHealth.Damage(bulletDamage);
        }
        transform.gameObject.SetActive(false);
    }
Exemple #7
0
 /// <inheritdoc />
 public DamageSummary SufferDamage(int damage)
 {
     return(new DamageSummary
     {
         InitialHealth = _health.Total(),
         Damaged = true,
         Defeated = _health.Damage(damage),
         RemainingHealth = _health.Total()
     });;
 }
Exemple #8
0
        private void OnCollisionEnter(Collision collision)
        {
            IHealth otherCompHealth = (IHealth)collision.gameObject.GetComponent(typeof(IHealth));

            if (otherCompHealth != null)
            {
                otherCompHealth.Damage(enemyAttack);
                CancelInvoke();
                transform.gameObject.SetActive(false);
            }
        }
Exemple #9
0
 /// <summary>
 /// Handles Collisions with Objects
 /// </summary>
 /// <param name="collision">Collision that occurred</param>
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collisionLayer.HasLayer(collision.gameObject.layer))
     {
         IHealth health = collision.gameObject.GetComponent <IHealth>();
         if (health == null || collision.gameObject.layer == wallLayer)
         {
             HitWall(collision);
         }
         else if (health.Damage(data.Damage))
         {
             Effect(collision);
         }
     }
 }
Exemple #10
0
    private void OnTriggerEnter(Collider other)
    {
        IHealth damageable = other.gameObject.GetComponent <IHealth>();

        if (damageable != null)
        {
            if (EventManager.OnDamagedSomething != null)
            {
                EventManager.OnDamagedSomething(transform.name, other.transform.name, damageType, damage);
            }

            damageable.Damage(bulletSource, damageType, damage);
            Destroy(this.gameObject);
        }
    }
    void OnCollisionEnter(Collision other)
    {
        IHealth health = other.gameObject.GetComponent <IHealth> ();

        if (health != null)
        {
            if (health.Health < 1)
            {
                return;
            }

            //if (!PseudoRandom.Instance.SequenceMod (8))
            //	return;

            health.Damage(10);

            GameObject splatterInstance = GameObject.Instantiate(splatterPrefab, transform.position, transform.rotation) as GameObject;
        }
    }
Exemple #12
0
        /// <inheritdoc />
        public DamageSummary SufferDamage(int damage)
        {
            var summary = new DamageSummary();

            // If we have a shield, remove it.
            if (_shield != null && _shield.StillAvailable())
            {
                _shield.DamageShield(damage);
            }
            else
            {
                summary.Damaged         = true;
                summary.InitialHealth   = _health.Total();
                summary.Defeated        = _health.Damage(damage);
                summary.RemainingHealth = _health.Total();
            }

            return(summary);
        }
Exemple #13
0
        void Update()
        {
            if (Input.GetKeyUp("s") && BossHealth.CurrentHP > 0)
            {
                // Stop the previous lerp. Update the health and start a new lerp.
                BossHealth.Damage(10);

                StopCoroutine("LerpHealth");
                if (BossHealth.CurrentHP > 0 && BossHealth.CurrentHP < (ColorIndex - 1) * OneBarHP)
                {
                    // Update the foreground and background hp bar colors.
                    ColorIndex--;
                    ForegroundBar.color = BarColors[ColorIndex];
                    BackgroundBar.color = BarColors[ColorIndex - 1];
                    // New HP bar starts at full.
                    ForegroundBar.fillAmount = 1;
                }
                StartCoroutine("LerpHealth");
            }
        }
Exemple #14
0
    public override void Shoot()
    {
        if (cooldownTimer >= cooldown)
        {
            cooldownTimer = 0f;

            for (int i = 0; i < pellets; i++)
            {
                Vector3 vector = GetUnitCircle(i);

                dummyPoint.localPosition = new Vector3(vector.x, vector.y, dummyPointDistance);

                Ray ray = new Ray(emitTransform.position, dummyPoint.position - emitTransform.position);

                RaycastHit hit;
                Debug.DrawRay(emitTransform.position, dummyPoint.position - emitTransform.position, Color.blue, 1f);
                GameObject newLine = Instantiate(hitscanLine);

                LineRenderer line = newLine.GetComponent <LineRenderer>();
                line.SetPosition(0, emitTransform.position);
                line.SetPosition(1, dummyPoint.position);

                if (Physics.Raycast(ray, out hit))
                {
                    IHealth damageable = hit.collider.gameObject.GetComponent <IHealth>();

                    if (damageable != null)
                    {
                        int damage = UnityEngine.Random.Range(minDamage, maxDamage + 1);

                        damageable.Damage(transform.root.gameObject, damageType, damage);

                        if (EventManager.OnDamagedSomething != null)
                        {
                            EventManager.OnDamagedSomething(transform.root.name, hit.collider.transform.root.name, damageType, damage);
                        }
                    }
                }
            }
        }
    }
Exemple #15
0
 public override void Damage(float damage)
 {
     sharedHealth.Damage(damage * damageMultiplier);
     Debug.Log(damageMultiplier);
 }