Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        Debug.DrawRay(transform.position, transform.forward);
        if (!moving)
        {
            FindSelectableTiles();
            CheckSwipe();
            CheckTab();

            if (currentTile == null)//Object is deleted (Wall)
            {
                MoveToTile(wallGround);
            }
            else
            {
                switch (currentTile.tag)
                {
                case "WallTile":
                    break;

                case "StoneResourceTile":
                    if (resourceActionTick.IsAction())
                    {
                        Resources.AddStone();
                        OnInformationUpdated();
                        animator.SetTrigger("PickUp");
                    }
                    break;

                case "AmmoResourceTile":
                    if (resourceActionTick.IsAction())
                    {
                        Resources.AddAmmo();
                        OnInformationUpdated();
                        animator.SetTrigger("PickUp");
                    }
                    break;

                case "RepairTile":
                    if (repairActionTick.IsAction())
                    {
                        var go = currentTile.GetGameObject(Vector3.forward); //Get Gameobject in front (Wall)

                        if (go != null)                                      //Wall already down when wall is null
                        {
                            var wall = go.GetComponent <Tile>();

                            if (wall != null && Resources.Stone > 0)    //Avoid enemy attack and stones available
                            {
                                if (wall.Repair(RepairEfficiencyPerStone))
                                {
                                    Resources.UseStone();
                                    OnInformationUpdated();
                                    animator.SetTrigger("Repair");
                                }
                            }
                        }
                    }
                    break;

                case "BaseTile":
                    break;

                case "Wall":
                    if (shootActionTick.IsAction())
                    {
                        if (Resources.Ammo > 0)
                        {
                            int row = Int32.Parse(currentTile.transform.parent.name.Split('(')[1].Split(')')[0]);    //TODO refactor read of row

                            if (transform.GetComponent <Shoot>().Shooting(row, damage))
                            {
                                Resources.UseAmmo();
                                OnInformationUpdated();
                            }
                        }
                    }

                    wallGround = currentTile.GetWallGroundOfRow();
                    break;
                }
            }
        }
        else
        {
            Move();
            animator.Play("Run");
        }
    }