public void Fire()
    {
        if (CanShoot())
        {
            foreach (var gun in guns)
            {
                bulletInstance = GameObjectsManager.GetObject("bullet");

                if (bulletInstance == null)
                {
                    bulletInstance = (GameObject)Instantiate(bullet, gun.position, gun.rotation);
                }
                else
                {
                    bulletInstance.transform.position = gun.position;
                    bulletInstance.transform.rotation = gun.rotation;
                    bulletInstance.gameObject.SetActive(true);
                }

                bulletScript              = bulletInstance.GetComponent <Bullet>();
                bulletScript.damage       = damage;
                bulletScript.affectsScore = affectsScore;

                bulletInstance = null;
            }

            this.audio.PlayOneShot(this.shotSound);
            Reload();
        }
    }
示例#2
0
        private static void ReadMessage(int id, dynamic obj)
        {
            switch (id)
            {
            case 0:
                int objectId = (int)obj.id;
                int baseId   = (int)obj.bId;
                int x        = (int)obj.x;
                int y        = (int)obj.y;

                try
                {
                    var mobModel = Script.Call <dynamic>("getMobModel", baseId);
                    GameObject.Instantiate <Character>(objectId, x, y, 64, 64, mobModel.resource);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Err:" + objectId);
                    Console.WriteLine(ex.ToString());
                }
                break;

            case 1:
                if (GameObjectsManager.GetObject((int)obj.id, out GameObject go))
                {
                    GameObject.Destroy(go);
                }
                break;

            case 2:
                if (GameObjectsManager.GetObject((int)obj.id, out Character c))
                {
                    c.SetDestination((int)obj.x, (int)obj.y);
                }
                break;

            case 3:
                GameController.Instance.SetMap((int)obj.mapId);
                if (GameObjectsManager.GetObject((int)obj.id, out Character pl))
                {
                    GameController.Instance.SetPlayer(pl);
                    GameController.Instance.player.SetStat(Stat.LVL, (int)obj.lvl);
                    GameController.Instance.player.SetStat(Stat.EXP, (int)obj.exp);
                }
                break;

            case 4:
                GameController.Instance.SetMap((int)obj.mapId);
                GameController.Instance.player.SetPosition((int)obj.x, (int)obj.y);
                break;

            case 5:
                Stat stat = (Stat)(int)obj.stat;
                if (GameObjectsManager.GetObject((int)obj.id, out Character t))
                {
                    t.SetStat(stat, (int)obj.val);
                }
                break;

            case 6:
                DbUniqueItem[] items = JSON.Parse <DbUniqueItem[]>((string)obj.items);
                foreach (var item in items)
                {
                    Script.Call("setInventorySlot", item.slot, item.baseId);
                }
                break;
            }
        }