public void shieldBreakCheck()
    {
        int[] keys = new int[brokenShield.Keys.Count];
        brokenShield.Keys.CopyTo(keys, 0);
        foreach (int index in keys)
        {
            if (deployedShields.ContainsKey(index) && deployedShields[index] != null)
            {
                GameObject   shieldObject = deployedShields[index];
                shieldScript shield       = shieldObject.GetComponent <shieldScript>();

                if (shield.broken || shield.health <= 0)
                {
                    brokenShield[index] = true;
                    shield.destoryShield();
                    deployedShields.Remove(index);
                }
            }
        }
    }
Ejemplo n.º 2
0
    protected bool hitShield(unitScript unit, unitScript clickedUnit)
    {
        Ray   ray      = new Ray(unit.transform.position + new Vector3(0, 1, 0), (clickedUnit.transform.position + new Vector3(0, 1, 0) - unit.transform.position + new Vector3(0, 1, 0)));
        float distance = Vector3.Distance(unit.transform.position, clickedUnit.transform.position);

        RaycastHit[] hits = Physics.RaycastAll(ray, distance).OrderBy(h => h.distance).ToArray();

        foreach (RaycastHit hit in hits)
        {
            if (hit.transform.gameObject.layer == 11)
            {
                shieldScript shield = hit.transform.gameObject.GetComponent <shieldScript>();
                if (shield.owner != controllerID)
                {
                    shield.takeDamage(unit.getCurrentWeapon().damage);
                }
                return(true);
            }
        }
        return(false);
    }