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.

I'm a beginner. I need to place a grid on my map in Unity and would like to access it to place a simple object on mouse click. How can I achieve this ?

I am unable to understand the grid functionality, should I have to write code for a 2D array or is there something in Unity that I can access, and what is basically the grid like something when I click my background image ?

share|improve this question
1  
possible duplicate of How do I place multiple objects in unity on a grid? –  user744 Sep 28 '11 at 16:12
    
I'm going to close/merge the other question since the user has a registered account associated with this question and I don't think I can merge them the other way. –  Tetrad Sep 28 '11 at 16:50

1 Answer 1

up vote 1 down vote accepted

This could be achieved in many ways. Unity has a pretty advanced positioning system as it is.

For just regular positioning look here http://unity3d.com/support/documentation/Manual/Positioning%20GameObjects.html

But without prior knowledge of whether you are looking to do this in code, it's hard to give a good answer. Try asking more specific, precise questions that you feel others could benefit from that can't be found out with a little bit of research

You can find scripts here.

http://www.unifycommunity.com/wiki/index.php?title=Scripts

And here's a list of tutorials and websites with tutorials.

http://www.unifycommunity.com/wiki/index.php?title=Tutorials

EDIT: ADDITION This shows how to place a tower, the towers positions are checked against in an arraylist is C#. Hopefully this should give you an idea of how to start.

public GameObject tower;
public GameObject tower2;
private ArrayList towerList = new ArrayList();
void Start()
{
    Vector3 towerPosition = new Vector3(1.0F, .75F, 1.0F);
    foreach (GameObject towerObject in towerList)
    {
        if (towerObject.transform.position == towerPosition)
        {
            // there is already a tower in that position
            return;
        }
    }

    tower = (GameObject)Instantiate(tower, new Vector3(1.0F, .75F, 1.0F), this.transform.rotation);
    towerList.Add(tower);

    // for proof of concept you we're going to try to place the tower
    // in the same position as the other one
    Vector3 towerPosition2 = new Vector3(1.0F, .75F, 1.0F);
    foreach (GameObject towerObject in towerList)
    {
        if (towerObject.transform.position == towerPosition2)
        {
            // there is already a tower in that position
            return;
        }
    }
    tower2 = (GameObject)Instantiate(tower2, new Vector3(1.0F, .75F, 1.0F), this.transform.rotation);
    towerList.Add(tower2);
}
share|improve this answer
    
ok thnx for the reply. As I am going to place towers on my plane so what my understanding up to now is to make 2D Array first on my plane and access it to place towers. right ? for e.g place tower on myArray[0,0] OR I should access plane position without making 2D array ? for eg. place tower on transform.position(x,y,z). The game I am going to make is like fieldrunners.com/media –  Syed Sep 29 '11 at 8:08
1  
Updated the answer to reflect some additional information. As you can see we put the towers into an arraylist in c#. When we go to place a tower you check against all elements in the arraylist and make sure that were not placing our new tower in the same position as a preexisting one –  Jacob S Griffith Sep 29 '11 at 14:08

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.