Search Unity

UnityScript, Output of function rounds off numbers when decimals are needed.

Discussion in 'Scripting' started by NeonTheCoder, Jun 1, 2015.

  1. NeonTheCoder

    NeonTheCoder

    Joined:
    Feb 1, 2014
    Posts:
    40
    I'm trying to make a randomly generating room/castle thing and I have this code that should technically work however when the blocks are created and their position is set the position number is rounded even though there needs to be a decimal for it to be seamless Here is my code
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var platformWood : Sprite;
    4. var platformCobble: Sprite;
    5. var platformShadow : Sprite;
    6. var lightCobble: Sprite;
    7. var contCobble_0: Sprite;
    8. var contCobble_1: Sprite;
    9. var contCobble_2: Sprite;
    10. var contCobble_3: Sprite;
    11. var lightCobbleWood: Sprite;
    12. var collumTop: Sprite;
    13. var collumMid: Sprite;
    14. var collumBottom: Sprite;
    15. var lightCobbleBorder: Sprite;
    16. var lightCobbleStairs: Sprite;
    17. var wood: Sprite;
    18. var windowTop: Sprite;
    19. var windowBottom: Sprite;
    20. var windowMid: Sprite;
    21.  
    22. var Player : GameObject;
    23.  
    24. var colliderCheckArea: float;
    25. var whatIsPlayer : LayerMask;
    26. private var currentSpawnArea = Vector2(0, 0);
    27.  
    28. private var CollumActive = 0;
    29. private var Platforms = 0;
    30. private var itemPos = 0;
    31. private var item = 0;
    32. private var blockSize : float;
    33. blockSize = 1.6;
    34.  
    35. function Start () {
    36.     currentSpawnArea = Vector2(transform.position.x, transform.position.y);
    37. }
    38.  
    39. function Update () {
    40.     while(Physics2D.OverlapCircle(currentSpawnArea, colliderCheckArea, whatIsPlayer)){
    41.         createChunk();
    42.  
    43.         currentSpawnArea.x += 16;
    44.     }
    45.  
    46.  
    47. }
    48.  
    49. function createNewGameObjectFromSprite(sprite : Sprite, Name : String, x : int, y : int){
    50.     var go : GameObject;
    51.     var render : SpriteRenderer;
    52.     go = new GameObject(Name);
    53.     render = go.AddComponent(SpriteRenderer);
    54.     render.sprite = sprite;
    55.     go.transform.position.x = x;
    56.     go.transform.position.y = y;
    57.     go.transform.localScale.x = 10;
    58.     go.transform.localScale.y = 10;
    59. }
    60.  
    61. function createChunk(){
    62.     //Creating Top Floor
    63.     for (var ft: int = 0; ft < 21; ft++){
    64.         createNewGameObjectFromSprite(lightCobbleWood, "Floor", (currentSpawnArea.x -10) + (ft * blockSize), currentSpawnArea.y -5);
    65.     }
    66.  
    67.     //Creating Under Floor
    68.     for (var fu: int = 0; fu < 6; fu++){
    69.         createNewGameObjectFromSprite(lightCobble, "FloorUnder", currentSpawnArea.x -10, (currentSpawnArea.y -5) -  (fu * blockSize));
    70.     }
    71. }
    What do I do so unity stops rounding the output?

    EDIT: Sorry guys I answered my own question like 5 minutes after I posted this, in createNewGameObjectFromSprite I had to change X, and Y, to floats from ints