Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ekta-Mehta-D · Mar 23, 2013 at 11:18 AM · gridcellarrange

Update Hex Grid Cell After Shooting

i have arranged game object sphere in hex grid cell and some of the cell i have filled with empty transform.

When i shoot i am positioning my bullet sphere in empty position.. but next time when i shoot , my previous bullet disappears.

So how to arrange game object in grid so that it persist until i destroy.

Code to generate grid :

 public var sphere : Transform[];   
    private var B : int = 0; 
    private var G : int = 1;  
    private var P : int = 2; 
    private var R : int = 3; 
    private var Y : int = 4;  
    private var E : int = 5;   
    
    public var  m : int= 12;
    public var n : int = 12;
  
    public var radius : float = 0.5f;
    public var useAsInnerCircleRadius : boolean = true;
  
    private var go : GameObject;
    private  var offsetX : float;
    private var offsetY : float;
  
    private var formation  = [   [E ,E ,E ,E, E, E, B, Y, Y  ],
                                    [E ,E ,E ,E, E, E, Y, Y, Y  ],
                                  [E ,E ,E ,E, E, E, Y, G, G  ],
                                    [E ,E ,E ,E, E, E, P, R, G  ],
                                 [E ,E ,E ,E, E, E, R, R, R  ],
                                 [E ,E ,E ,E, E, E, R, R, R  ],
                                  [E ,E ,E ,E, E, E, P, B, B  ],
                                  [E ,E ,E ,E, E, E, B, Y, B  ],                                 
                                  [E ,E ,E ,E, E, E, G, E, Y  ] ];
                                          
    function Start() {
       CreateGrid();
       //StartAdjustments();
    }
  
 function HexOffset( x : int, y : int) : Vector2 
 {
       var position : Vector2 = Vector2.zero;
  
       if( y % 2 == 0 ) {
          position.x = x ;//* offsetX;
          position.y = y ;//* offsetY;
       }
       else {
          position.x = ( x + 0.5f );// * offsetX;
          position.y = y;// * offsetY;
       }     
       return position;
 }
 function CreateGrid()
 {
     go = GameObject.Find("Grid");
     var unitLengthv : float = ( useAsInnerCircleRadius )? (radius / (Mathf.Sqrt(3)/2)) : radius;
     
     offsetX =  Mathf.Sqrt(3);
     offsetY =  1.5f;
  
     for(var i : int = 0; i < formation.length; i++ )
     {
          for(var  j : int = 0; j < formation[i].length; j++ ) 
          {
             var  hexpos : Vector2 = HexOffset( i, j );
             var pos : Vector3 = new Vector3( hexpos.x, hexpos.y, 0 ) + transform.position;
             var tempsphere : Transform = Instantiate(sphere[formation[i][j]], pos, Quaternion.identity );
             tempsphere.transform.parent = go.gameObject.transform;
             if(formation[i][j] != E)
             {
                     tempsphere.transform.rigidbody.constraints = RigidbodyConstraints.FreezeAll;
             }
             tempsphere.GetComponent(CellScript).position = pos;
             tempsphere.GetComponent(CellScript).i = i;
             tempsphere.GetComponent(CellScript).j = j;
          }
     }
 }

code which i have tried :

 function OnCollisionEnter(collision : Collision )
 {        
     if(transform.parent == null)
     {      
         var gs : Grid = GameObject.Find("Grid").GetComponent(Grid);
         var hitColliders = Physics.OverlapSphere(collision.transform.position, 0.7);
         if(bubbleId.Equals(collision.gameObject.tag))
         {
              for (var i : int = 0; i < hitColliders.Length; i++) 
              {
                          
                    Destroy(hitColliders[i].gameObject);
                    gs.DestroySphere(hitColliders[i].gameObject.transform.GetComponent(CellScript).i ,hitColliders[i].gameObject.transform.GetComponent(CellScript).j , hitColliders[i].gameObject.transform.GetComponent(CellScript).position); 
                    Destroy(gameObject);           
              }
           }
          else
             {                            
                var contact : ContactPoint = collision.contacts[0];
             var pos : Vector3 = contact.point;    
             var t : Transform = ClosestTransform(pos);
             transform.position = t.position;
             transform.rotation = t.rotation;
             transform.rigidbody.velocity = Vector3.zero;
             transform.rigidbody.angularVelocity = Vector3.zero; 
             transform.rigidbody.isKinematic = true;
             
          }                                     
     }            
 }

cell script :

  public var  position : Vector3;
     public var color : String;
     public var i : int;
     public var j : int;

I am currently learning hex grid.. so pleaze guide me..

Thanks in advance for your support and help..

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Reduce draw call when drawing Grid! 0 Answers

How to name each grid cell in a grid... 0 Answers

GridLayout dynamic cell size based on object count 0 Answers

Grid based movement collision detection 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