Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by scayetanot · May 18, 2016 at 06:06 PM · prefabgrid based gameboardgame

2D Objects not well placed in the grid

Hi I have followed the Board game tutorial and I have been able to place gameobjects. My concern is that the obj are not well placed. it's seems that the grid - cell is too small. Check the picalt text

I was expected the grid to adapt itslef to the width and height of the prefab.

Any idea. the game is baed on 4 columns / 6 raws.

Merci

screen-shot-2016-05-14-at-101641.png (22.2 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FortisVenaliter · May 18, 2016 at 06:27 PM 0
Share

What grid? I don't see one there... Where's the logic that's supposed to manage the grid?

avatar image Gaming-Dudester FortisVenaliter · May 19, 2016 at 10:27 PM -1
Share

liekaboss

avatar image scayetanot FortisVenaliter · May 19, 2016 at 11:12 PM 0
Share

Here is the code I use

using UnityEngine; using System; using System.Collections.Generic;

using Random = UnityEngine.Random;

public class Board$$anonymous$$anager : $$anonymous$$onoBehaviour {

 [Serializable]
 public class Count
 {
     public int $$anonymous$$imum;
     public int maximum;

     public Count (int $$anonymous$$, int max)
     {
         $$anonymous$$imum = $$anonymous$$;
         maximum = max;
     }
 }

 public int columns = 4;
 public int rows = 6;

 // To be replaces by a defined level.
 // random is used.
 public Count planets = new Count(2,4);
 public Count blackholes = new Count(0,2);
 public Count teleports = new Count(0,2); 
 public Count belt = new Count(0,4);

 //public GameOjbect shuttleTile;
 public GameObject station1Tile;
 public GameObject station2Tile;
 public GameObject station3Tile;
 public GameObject station4Tile;

 public GameObject[] planetTile;
 public GameObject[] blackholeTile;
 public GameObject[] teleportTile;
 public GameObject[] asteroidbelt;

 private Transform boardHolder;
 private List<Vector3> gridPositions = new List<Vector3>();

 void InitialiseList(){
     gridPositions.Clear ();

     for (int x = 1; x < columns; x++) {
         for (int y = 1; y < rows ; y++) {
             gridPositions.Add (new Vector3 (x, y, 0f));
         }
     }
 }

 void BoardSetup(){
     boardHolder = new GameObject ("Board").transform;
 }

 void LayoutPlanetPlace(GameObject[] tileArray){
     GameObject tileChoice = tileArray[Random.Range(0, tileArray.Length)];
     Instantiate (tileChoice, new Vector3(2, 2, 0f), Quaternion.identity);

     tileChoice = tileArray[Random.Range(0, tileArray.Length)];
     Instantiate (tileChoice, new Vector3(3, 4, 0f), Quaternion.identity);
     tileChoice = tileArray[Random.Range(0, tileArray.Length)];
     Instantiate (tileChoice, new Vector3(1, 5, 0f), Quaternion.identity);
 }

 public void SetupScene(int level){
     BoardSetup ();
     InitialiseList ();
     LayoutPlanetPlace (planetTile);

     //Exit
     Instantiate (station1Tile, new Vector3(columns-1, rows-1, 0f),Quaternion.identity);

 }

}

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by goleminthegears · Jan 16, 2017 at 07:37 AM

Is the "Pixel Per Unit" of the sprite the same across all your prefabs for your grid? If not, it could throw off the construction of your grid.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Spawn after completion of drag and drop 0 Answers

Changing position of instantiated prefab from empty gameobject which is the location of the prefab when instantiating. 0 Answers

Can I force z position to match prefab when it's dragged onto scene? 1 Answer

All instances of a an object are being updated at once instead of the object in question. 1 Answer

How to create GameObject without adding it to scene? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges