Пример #1
0
    void FixedUpdate()
    {
        float   inputX         = Input.GetAxisRaw("Horizontal");
        float   inputY         = Input.GetAxisRaw("Vertical");
        Vector2 targetVelocity = new Vector2(inputX, inputY) * speed;

        rb.velocity = IsometricUtils.IsoFrom2D(targetVelocity);
        anim.SetFloat("speed", rb.velocity.magnitude);

        if (inputX > 0 && inputY > 0)
        {
            anim.SetInteger("dir", 0);
        }
        else if (inputX > 0 && inputY < 0)
        {
            anim.SetInteger("dir", 1);
        }
        else if (inputX < 0 && inputY > 0)
        {
            anim.SetInteger("dir", 3);
        }
        else if (inputX < 0 && inputY < 0)
        {
            anim.SetInteger("dir", 2);
        }
        else if (inputY > 0)
        {
            anim.SetInteger("dir", 3);
        }
        else if (inputY < 0)
        {
            anim.SetInteger("dir", 1);
        }
        else if (inputX > 0f)
        {
            anim.SetInteger("dir", 0);
        }
        else if (inputX < 0f)
        {
            anim.SetInteger("dir", 2);
        }

        if (Input.GetMouseButtonDown(0) && playerObjects.CanShoot())
        {
            ShootItem();
        }
    }
Пример #2
0
    public IEnumerator ParseLevelFile(TextAsset csv, Vector3 startingPoint, Color blockTint)
    {
        buildRoomPreparation();
        Vector3 startingPointRounded = IsometricUtils.TranslateSceneToIso(startingPoint);

        print("csv starting point: " + startingPointRounded);
        int xOffset = Mathf.RoundToInt(startingPointRounded.x);
        int yOffset = Mathf.RoundToInt(startingPointRounded.y);

        breakPoint.position  = startingPoint;
        originPoint.position = startingPoint;
        string[] rows = csv.text.Split("\n"[0]);

        //starts on bottom row of csv.
        print("rows.length: " + rows.Length);
        //i = Y value
        for (int i = 0; i <= rows.Length - 2; i++)
        {
            int     yCoord = i + yOffset;
            RowInfo row;
            if (!rowDatabase.ContainsKey(yCoord))
            {
                print("creating new row. " + yCoord);
                row          = new RowInfo();
                row.rowIndex = yCoord;
                rowDatabase.Add(yCoord, row);
            }
            else
            {
                print("appending block to existing row.");
                row = rowDatabase[i];
            }
            print("row (yValue): " + i);
            string[] rowTiles = rows[(rows.Length - 2) - i].Split(',');
            //j = X value
            for (int j = 0; j < rowTiles.Length; j++)
            {
                print("parsing " + rowTiles[j] + " to int");
                int setPieceIndex = int.Parse(rowTiles[j]);
                if (setPieceIndex != 0)
                {
                    yield return(new WaitForSeconds(spawnSpeed));

                    int xCoord = j + xOffset;
                    print(xCoord + ", " + yCoord + " tile value: " + setPieceIndex);
                    TileInfo tile = new TileInfo();
                    if (setPieceIndex > 0 && blockSet[setPieceIndex] != null)
                    {
                        print("blockset[setpieceIndex] = " + blockSet[setPieceIndex]);
                        GameObject GO = PoolManager.instance.ReuseObject(blockSet[setPieceIndex], originPoint.position, Quaternion.identity);
                        GO.transform.parent = this.transform;
                        GO.transform.name  += (" (" + xCoord + ", " + yCoord + ")");
                        tile = GO.GetComponent <TileInfo>();
                        tile.transform.GetChild(0).GetComponent <SpriteRenderer>().color = blockTint;
                    }
                    tile.initializeTile(new Vector2(xCoord, yCoord), originPoint.position);
                    row.tiles.Add(xCoord, tile);
                }
                originPoint.position += new Vector3(0.5f, 0.25f, 0);
                compCol.GenerateGeometry();
            }
            LineBreak();
        }
        originPoint.position = Vector3.zero;
    }