예제 #1
0
    public void UpDown(int offSet, string direction)
    {
        int[] location = _grid.findObject(gameObject);
        print(location[0] + "x y" + location[1]);
        GameObject target = _grid.CheckTile(location[0], location[1] + offSet);

        if (target == null)
        {
            _grid.Up(gameObject);
        }
        else
        {
            switch (target.tag)
            {
            case "gem":
                _Points.AddPoints(1);
                _grid.MoveInDirection(direction, gameObject);
                break;

            case "gem2":
                _Points.AddPoints(2);
                _grid.MoveInDirection(direction, gameObject);
                break;

            case "gem3":
                _Points.AddPoints(3);
                _grid.MoveInDirection(direction, gameObject);
                break;

            case "dirt":
                _grid.MoveInDirection(direction, gameObject);
                break;

            case "finish":
                GameObject.FindGameObjectWithTag("LevelSpawner").GetComponent <SpawnScript>().NextLevel();
                break;

            default:
                break;
            }
        }
    }
    public void UpDown(string direction)
    {
        if (moveTimer.done)
        {
            Vector2 location = _grid.findLocation(gameObject);
            Vector2 targetLocation;
            switch (direction)
            {
            case "up":
                targetLocation = new Vector2(0, 1);
                break;

            case "down":
                targetLocation = new Vector2(0, -1);
                break;

            default:
                targetLocation = new Vector2(1, 1);
                break;
            }
            GameObject target = _grid.CheckTile(location + targetLocation);
            if (target == null)
            {
                _grid.MoveRelative(targetLocation, gameObject);
                moveTimer.Move(location, location + targetLocation, speed);
            }
            else
            {
                switch (target.tag)
                {
                case "gem":
                    _Points.AddPoints(1);
                    _grid.MoveRelative(targetLocation, gameObject);
                    moveTimer.Move(location, location + targetLocation, speed);
                    break;

                case "gem2":
                    _Points.AddPoints(2);
                    _grid.MoveRelative(targetLocation, gameObject);
                    moveTimer.Move(location, location + targetLocation, speed);
                    break;

                case "gem3":
                    _Points.AddPoints(3);
                    _grid.MoveRelative(targetLocation, gameObject);
                    moveTimer.Move(location, location + targetLocation, speed);
                    break;

                case "dirt":
                    _grid.MoveRelative(targetLocation, gameObject);
                    moveTimer.Move(location, location + targetLocation, speed);
                    break;

                case "finish":
                    GameObject.FindGameObjectWithTag("LevelSpawner").GetComponent <SpawnScript>().NextLevel();
                    break;

                default:
                    break;
                }
            }
        }
    }