Example #1
0
    void OnCollisionEnter2D(Collision2D coll)
    {
        Debug.Log(coll.contacts[0].normal.ToString());


        if (coll.gameObject.name == "Hero")
        {
            //Check who killed who. If contact happend from the top player killed the enemy. Else player died.
            if (coll.contacts[0].normal.x > -1f && coll.contacts[0].normal.x < 1f && coll.contacts[0].normal.y <-0.8f && coll.contacts[0].normal.y> -1.8f)
            {
                this.enemyRigidbody2d.velocity = new UnityEngine.Vector2(0, enemyRigidbody2d.velocity.y);

                coll.rigidbody.AddForce(new Vector2(0f, 4900f));
                this.GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, -200f));
                /*EnemyDead = true;*/
                SoundManager.Instance.PlaySound("enemyDeadAudio");
                Debug.Log("Monster died");



                this.gameObject.SetActive(false);
                Instantiate(enemyExplosion, this.transform.position, this.transform.rotation);

                //Invoke("iDied",1f);

                //Destroy(this.gameObject);
            }
            else
            {
                Debug.Log("GG");
                EventDef.LevelEvent eventId = EventDef.LevelEvent.PlayerDie;
                AppMgr.Instance.SendEvent((int)eventId, this.gameObject);
            }
        }
    }
Example #2
0
    public bool HandleEvent(int id, object param1, object param2)
    {
        EventDef.LevelEvent evid = (EventDef.LevelEvent)id;
        switch (evid)
        {
        case EventDef.LevelEvent.PlayerDie:
            //Instantiate(DeadExplosion, HeroCtrl.Instance.heroPosition, HeroCtrl.Instance.heroRotation);
            UIMgr.Instance.ShowUI(UIDef.DieUI, typeof(DieCtrl), this, mCurrentLevel);
            return(false);

        case EventDef.LevelEvent.GameOver:
            Log.Debug("---------Game Compliteļ¼");

            if (!AppMgr.Instance.OpenLevels.Contains(mCurrentLevel + 1))
            {
                AppMgr.Instance.AddOpenLevel(mCurrentLevel + 1);
            }

            UIMgr.Instance.ShowUI(UIDef.WinUI, typeof(WinCtrl), this, mCurrentLevel);

            return(false);

        case EventDef.LevelEvent.SaveGame:
        {
            GameObject go = (GameObject)param1;
            AppMgr.Instance.HeroPos = go.transform.position;
        }
            return(false);
        }

        return(false);
    }
Example #3
0
    public bool HandleEvent(int id, object param1, object param2)
    {
        EventDef.LevelEvent evid = (EventDef.LevelEvent)id;
        switch (evid)
        {
        case EventDef.LevelEvent.PlayerDie:
            isDie = true;
            playerRigidbody2D.velocity = new UnityEngine.Vector2(0, playerRigidbody2D.velocity.y);
            playerAnimator.SetBool("Die", isDie);
            this.gameObject.SetActive(false);
            Instantiate(DeadExplosion, transform.position, transform.rotation);

            return(false);

        case EventDef.LevelEvent.GameOver:
            isGameOver = true;
            playerRigidbody2D.velocity = new UnityEngine.Vector2(0, playerRigidbody2D.velocity.y);
            playerAnimator.SetFloat("Speed", 0);
            return(false);
        }

        return(false);
    }