Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Using Unity 5.1 and was following a tutorial for generating a grid for a Minesweeper-style game. Link to the tutorial for reference: http://gamedevelopment.tutsplus.com/tutorials/build-a-grid-based-puzzle-game-like-minesweeper-in-unity-setup--cms-21361

Tutorial is Unity 4, but I don't think it should matter.

Here's my code:

public GameObject tilePrefab;
public int numOfTiles = 10;
public float distanceBetweenTiles = 1f;

void Start () {
    CreateTiles();
}

void CreateTiles () {
    float xOffset = 0f;

    for (int tilesCreated = 0; tilesCreated < numOfTiles; tilesCreated++) {
        Vector3 positionVar = new Vector3(transform.position.x + xOffset, transform.position.y, transform.position.z);
        xOffset += distanceBetweenTiles;
        Instantiate(tilePrefab, positionVar, transform.rotation);
    }
}

Essentially, the problem is that when I coded the spacing algorithm, Unity decided to ignore the spacing of 1f, but instead do 10,000. No matter the number I substitute for "distanceBetweenTiles", Unity spaces the cubes by 10,000 points. I'm assuming it has to do with how Unity is handling the float numbers, but I'm not quite sure, considering the number I substitute doesn't seem to matter. I've included a screenshot of Unity running the script and the inspector view of the giant X position. Thanks so much in advance![Unity number problem]1

share|improve this question

1 Answer 1

Check the script in the inspector (click on the object that holds it). Looks like you changed the value there, which will override the default value due to how Unity's serialization system works. Thus, the default value specified in the script will be ignored.

share|improve this answer
1  
You can remove the public modifier if you don't need to change it in the inspector and you want to avoid these kinds of issues in the future. –  Byte56 2 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.