コード例 #1
0
    public void ToggleState()
    {
        State = !State;

        foreach (BasicTile Tile in ConnectedTiles)
        {
            SpikeTile SpecialTile = Tile.GetComponent <SpikeTile>();
            SpecialTile.State = !SpecialTile.State;
        }
    }
コード例 #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D))
        {
            playerManager.StepsTaken++;
            Vector3 OldPos = transform.position;
            MovePos();

            if (OldPos != transform.position)
            {
                if (StandingTile.ToggleType)
                {
                    PressurePlate pressurePlate = StandingTile.GetComponent <PressurePlate>();
                    pressurePlate.ToggleState();
                }
                else if (StandingTile.SpikeType)
                {
                    SpikeTile spike = StandingTile.GetComponent <SpikeTile>();
                    if (spike.State)
                    {
                        playerManager.GetHurt();
                    }
                }
                else if (StandingTile.KeyType)
                {
                    KeyTile key = StandingTile.GetComponent <KeyTile>();
                    TotalKeys = key.ToggleState(TotalKeys);
                }
                else if (StandingTile.ChestType)
                {
                    LockedChest chest = StandingTile.GetComponent <LockedChest>();
                    TotalKeys = chest.ToggleState(TotalKeys);
                }
                else if (StandingTile.EndType)
                {
                    EndTile Finish = StandingTile.GetComponent <EndTile>();
                    Finish.ToggleState();
                    MyFiredArrows?.Invoke();
                }
            }
        }
    }
コード例 #3
0
ファイル: GridManager.cs プロジェクト: Youcheny/GridGod
    private void GenerateConsumableFromCSV(string filepath, string filename)
    {
        print("entering");
        Consumable coin = new Consumable()
        {
            consumable = (GameObject)Instantiate(Resources.Load("Coin")),
            type       = "CoinTile"
        };
        Consumable transparent = new Consumable()
        {
            consumable = (GameObject)Instantiate(Resources.Load("TransparentTile")),
            type       = "TransparentTile"
        };
        Consumable stepAdder = new Consumable()
        {
            consumable = (GameObject)Instantiate(Resources.Load("StepAdder")),
            type       = "StepAdderTile"
        };
        Consumable spike = new Consumable()
        {
            consumable = (GameObject)Instantiate(Resources.Load("TrapTile")),
            type       = "SpikeTile"
        };

        string[,] GridCSV = CsvUtil.readData(filepath, filename);
        rows = GridCSV.GetLength(0);
        cols = GridCSV.GetLength(1);

        float centerOffsetX = -cols * tileSize / 2; // center
        float centerOffsetY = rows * tileSize / 2;


        for (int i = 0; i < GridCSV.GetLength(0); i++)
        {
            List <Consumable> consumableRow = new List <Consumable>();

            for (int j = 0; j < GridCSV.GetLength(1); j++)
            {
                GameObject consumable;

                if (GridCSV[i, j] == "C")
                {
                    consumable = (GameObject)Instantiate(coin.consumable, transform);
                    Coin coinTile = new Coin()
                    {
                        consumable = consumable,
                        type       = "CoinTile"
                    };
                    consumableRow.Add(coinTile);
                }
                else if (GridCSV[i, j] == "S")
                {
                    consumable = (GameObject)Instantiate(stepAdder.consumable, transform);
                    StepAdder stepAdderTile = new StepAdder()
                    {
                        consumable = consumable,
                        type       = "StepAdderTile"
                    };
                    consumableRow.Add(stepAdderTile);
                }
                else if (GridCSV[i, j] == "T")
                {
                    consumable = (GameObject)Instantiate(spike.consumable, transform);
                    SpikeTile spikeTile = new SpikeTile()
                    {
                        consumable = consumable,
                        type       = "SpikeTile"
                    };
                    consumableRow.Add(spikeTile);
                }
                else
                {
                    consumable = (GameObject)Instantiate(transparent.consumable, transform);
                    TransparentTile transparentTile = new TransparentTile()
                    {
                        consumable = consumable,
                        type       = "TransparentTile"
                    };
                    consumableRow.Add(transparentTile);
                }

                float posX = j * tileSize + centerOffsetX;
                float posY = i * -tileSize + centerOffsetY;

                consumable.transform.position = new Vector2(posX, posY);
            }

            Consumables.Add(consumableRow);
        }



        Destroy(coin.consumable);
        Destroy(transparent.consumable);
        Destroy(stepAdder.consumable);
        Destroy(spike.consumable);
    }