예제 #1
0
    protected void CheckHitboxes()
    {
        collisionDictionary.Clear();
        //Create dictionary of hitboxes that hit fighters to sort them with hitbox id
        foreach (IHitbox hitbox in list)
        {
            List <GameObject> collisions = hitbox.GetCollisionList();
            foreach (GameObject collider in collisions)
            {
                if (collisionDictionary.ContainsKey(collider))
                {
                    collisionDictionary[collider].Add(hitbox);
                }
                else
                {
                    List <IHitbox> value = new List <IHitbox>();
                    value.Add(hitbox);
                    collisionDictionary.Add(collider, value);
                }
            }
        }
        //Remove Fighters who have shield collision
        List <GameObject> shieldingFighters = new List <GameObject>();

        foreach (KeyValuePair <GameObject, List <IHitbox> > p in collisionDictionary)
        {
            if (p.Key.tag == "Shield")
            {
                shieldingFighters.Add(p.Key.transform.root.gameObject);
                victims.Add(p.Key.transform.root.gameObject);
            }
        }
        foreach (GameObject fighter in shieldingFighters)
        {
            collisionDictionary.Remove(fighter);
        }
        //Remove all but Hitbox with lowest ID for each fighter and process the highest ID hitbox
        foreach (KeyValuePair <GameObject, List <IHitbox> > p in collisionDictionary)
        {
            //Find hitbox with lowest ID
            IHitbox topIDHitbox = p.Value[0];
            int     topID       = 10;
            foreach (IHitbox hitbox in p.Value)
            {
                if (hitbox.ID < topID)
                {
                    topIDHitbox = hitbox;
                    topID       = hitbox.ID;
                }
            }
            //Debug.Log("Fighter: " + p.Key.name + ", Hitbox Chosen: " + topID);
            //Add to the victims list to prevent hitting again
            if (victims.Contains(p.Key))
            {
                continue;
            }
            victims.Add(p.Key);
            topIDHitbox.OnHit(p.Key);
        }
    }
예제 #2
0
 public void OnHit()  //gets played when something collides with the hitbox
 {
     if (hitController != null)
     {
         hitController.OnHit();
     }
     if (useHitSparks)
     {
         ParticleSystem sparks = ObjectPooler.PoolObject("HitSparks").GetComponent <ParticleSystem>();
         sparks.gameObject.transform.position = transform.position;
         sparks.gameObject.SetActive(true);
         sparks.Play();
     }
 }