Exemplo n.º 1
0
    protected void OnCollisionEnter2D(Collision2D collision)
    {
        IKillable killable = collision.transform.root.gameObject.GetComponent <IKillable>();

        if (killable != null)
        {
            GetComponent <EdgeCollider2D>().isTrigger = true;
            AudioManager.Instance.PlaySoundIfNotPlaying(AudioClipNames.SmallSquish);
            killable.Die(CauseOfDeath.Spikes, collision.GetContact(0).point, collision.collider);
        }
    }
Exemplo n.º 2
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (1 << collision.gameObject.layer == playerLayer)
     {
         IKillable killable = collision.gameObject.GetComponent <IKillable>();
         if (killable == null)
         {
             collision.transform.root.gameObject.GetComponent <IKillable>();
         }
         if (killable != null)
         {
             killable.Die(CauseOfDeath.FellOutOfMap, default, collision.collider);
    public static void KillObject(Transform obj, float destroyTime)
    {
        //удаление объекта из списка выделенных объектов каждого игрока
        foreach (Player player in GameManager.Players)
        {
            HumanPlayer humanPlayer = player as HumanPlayer;
            if (humanPlayer != null)
            {
                humanPlayer.ObjectSelector.RemoveFromSelectedObjectList(obj);
            }
        }
        //transform.parent = null;
        RemoveFromPlayerObjectList(obj);
        obj.gameObject.layer = GameManager.DefaultLayer;//ставим layer по умолчанию, чтобы объект больше не влиял на игровой мир

        IKillable AI = obj.GetInterfaceComponent <IKillable>();

        if (AI != null)
        {
            AI.Die();
        }

        UnitFactory unitFactory = obj.GetComponent <UnitFactory>();

        if (unitFactory != null)
        {
            Object.Destroy(unitFactory);
        }

        BuildingGrid grid = obj.GetComponent <BuildingGrid>();

        if (grid != null)
        {
            Object.Destroy(grid);
        }

        Rigidbody rb = obj.rigidbody;

        if (rb != null)
        {
            rb.isKinematic = true;
            Object.Destroy(rb);
        }

        Collider c = obj.collider;

        if (c != null)
        {
            c.enabled = false; //Object.Destroy(c);
        }
        Object.Destroy(obj.gameObject, destroyTime);
    }
Exemplo n.º 4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!_attacking)
        {
            return;
        }

        if (collision.GetComponent(typeof(IKillable)))
        {
            IKillable obj = collision.GetComponent <IKillable>();
            obj.Die();
        }
    }
Exemplo n.º 5
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        IKillable killable = collision.gameObject.GetComponent <IKillable>();

        if (killable == null)
        {
            killable = collision.transform.root.gameObject.GetComponent <IKillable>();
        }
        if (killable != null)
        {
            AudioManager.Instance.PlaySound(AudioClipNames.LoudSquish);
            killable.Die(CauseOfDeath.SpikeWheel, collision.GetContact(0).point, collision.collider);
        }
    }
Exemplo n.º 6
0
 public KingdomCentre(string kingName, string[] royalGuardsNames, string[] footmenNames)
 {
     this.king = new King(kingName);
     AddServants(royalGuardsNames, footmenNames);
     functions = new Dictionary <string, Action <string> >()
     {
         { "Attack", (s) => king.Notify() },
         { "Kill", delegate(string name)
           {
               IKillable current = this.king.Observers.First(x => x.Name == name) as IKillable;
               current?.Die();
               this.king.RemoveDeadServants();
           } }
     };
 }
Exemplo n.º 7
0
 public void KillThemAll()
 {
     foreach (Enemy spawn in sceneContents.Enemies.ToArray())
     {
         IKillable killable = null;
         if (spawn)
         {
             killable = spawn.GetComponent <IKillable>();
         }
         if (killable != null)
         {
             killable.Die();
         }
     }
 }
Exemplo n.º 8
0
        void OnCollisionEnter2D(Collision2D collisionInfo)
        {
            GameObject collidedObject = collisionInfo.gameObject;

            if (collidedObject.tag != tagToKill)
            {
                return;
            }

            IKillable killable = collidedObject.GetComponent <IKillable>();

            if (killable != null)
            {
                killable.Die(gameObject);
            }
        }
Exemplo n.º 9
0
 public void InvokeCommand()
 {
     killable.Die();
 }