Esempio n. 1
0
    private void OnTriggerEnter(Collider other)
    {
        if (attackComponent == null)
        {
            attackComponent = GetComponentInParent <AttackComponent>();
        }

        AttackableComponent attackableComponent = other.GetComponent <AttackableComponent>();

        if (attackableComponent != null)
        {
            MyObject enemyObject = attackableComponent.GetComponent <MyObject>();
            if (!enemyObject.placed)
            {
                // Building has not been placed
                return;
            }

            if (enemyObject != attackComponent.myObject)
            {
                if (enemyObject.team != attackComponent.myObject.team)
                {
                    attackComponent.AddTargetInRange(attackableComponent, enemyObject.myObjectType);
                }
            }
        }
        else
        {
            attackableComponent = other.GetComponentInParent <AttackableComponent>();
            if (attackableComponent != null)
            {
                MyObject enemyObject = attackableComponent.GetComponentInParent <MyObject>();
                if (!enemyObject.placed)
                {
                    // Building has not been placed
                    return;
                }

                if (enemyObject != attackComponent.myObject)
                {
                    if (enemyObject.team != attackComponent.myObject.team)
                    {
                        attackComponent.AddTargetInRange(attackableComponent, enemyObject.myObjectType);
                    }
                }
            }
        }
    }
Esempio n. 2
0
    private void OnTriggerExit(Collider other)
    {
        if (attackComponent == null)
        {
            attackComponent = GetComponentInParent <AttackComponent>();
        }

        AttackableComponent attackableComponent = other.GetComponent <AttackableComponent>();

        if (attackableComponent != null)
        {
            MyObject enemyObject = attackableComponent.GetComponent <MyObject>();

            if (enemyObject != attackComponent.myObject)
            {
                if (enemyObject.team != attackComponent.myObject.team)
                {
                    attackComponent.RemoveTargetInRange(attackableComponent, enemyObject.myObjectType);
                }
            }
        }
        else
        {
            attackableComponent = other.GetComponentInParent <AttackableComponent>();
            if (attackableComponent != null)
            {
                MyObject enemyObject = attackableComponent.GetComponentInParent <MyObject>();

                if (enemyObject != attackComponent.myObject)
                {
                    if (enemyObject.team != attackComponent.myObject.team)
                    {
                        attackComponent.RemoveTargetInRange(attackableComponent, enemyObject.myObjectType);
                    }
                }
            }
        }
    }
Esempio n. 3
0
    IEnumerator MoveTowardsTarget()
    {
        Vector3 startPos = transform.position;

        for (float i = 0; i <= 1f; i += Time.deltaTime * 2f)
        {
            transform.position = Vector3.Lerp(startPos, target.transform.position, i);
            lineRenderer.SetPosition(0, transform.position);
            lineRenderer.SetPosition(1, transform.position + transform.forward);

            if (Vector3.Distance(transform.position, target.transform.position) < 1f)
            {
                target.ReceiveDamage(damage * AttackComponent.GetDamageModifier(damageType, target.GetComponent <MyObject>().myObjectType));
                if (hitSound != null)
                {
                    Instantiate(hitSound, transform.position, Quaternion.identity);
                }
                target = null;
                //Destroy(gameObject);
            }

            yield return(null);
        }
    }