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 Renoclaf · May 07, 2013 at 10:58 AM · c#listgrid

Grid 'Infection' though lists c#

Hi all

I've been working on a grid based game where tiles on the outside become 'infected'. The goal is to have the infection move in a semi-random nature towards the center of the grid. The grid tiles are created at the beginning of the level and added to a list "gridList", from here I add all perimeter tiles to the "perimList". The infection is then started through this

public void StartPoint(){

         int indexP = Random.Range (0, perimList.Count);
         int darkLength = darkList.Count;
         
         if(darkLength < perimLength){                            
             if(!darkList.Contains(perimList[indexP])){            
                 darkList.Add (perimList[indexP]);
                 Debug.Log ("dark");
                 string tileName;
                 tileName = perimList[indexP].name;
                 gameObject.SendMessage("RecPerimName", tileName);
                 }else{
             if(darkList.Contains (perimList[indexP])){
                 Recall(true);
                 }        
             }
          }
     }

This sends the name of the tile to a Manager script on the same object which then sets the tile texture to a dark color. If the tile is already dark it restarts.

I am unsure from this point as to the best method of making the infection spread to the center of the map. I tried using a series of list checks to move the infection in one tile, this works however it will get convoluted quickly if I have to check for each "ring" of the grid.

     public void PerimSpread(){
         
         int darkP = Random.Range (0, darkList.Count);
         if(darkList[darkP].transform.position.x == 0 || darkList[darkP].transform.position.x == (Size.x - 1) && darkList[darkP].transform.position.z != 0 && darkList[darkP].transform.position.z != (Size.z - 1)){
             if(darkList[darkP].transform.position.x == 0){
                 PerimXAdd (darkList[darkP]);
             }
             if(darkList[darkP].transform.position.x == (Size.x - 1)){
                 PerimXMinus (darkList[darkP]);
             }    
         }        
         if(darkList[darkP].transform.position.z == 0 || darkList[darkP].transform.position.z == (Size.z - 1) && darkList[darkP].transform.position.x != 0 && darkList[darkP].transform.position.x != (Size.z - 1)){
             if(darkList[darkP].transform.position.z == 0){
                 PerimZAdd (darkList[darkP]);
             }
             if(darkList[darkP].transform.position.z == (Size.z - 1)){
                 PerimZMinus(darkList[darkP]);
             }        
         }
         if(darkList[darkP].transform.position.z == 0 && (darkList[darkP].transform.position.x == 0)){
             PerimOrigin (darkList[darkP]);
         }    
         if(darkList[darkP].transform.position.z == (Size.z - 1) && darkList[darkP].transform.position.x == (Size.x - 1)){
             PerimEnd (darkList[darkP]);
         }    
     }

Sample function that is called from above;

 public void PerimXAdd(GameObject temp){
         Debug.Log ("PerimXAdd");
         for(int i = 0; i < gridList.Count; i++){
             if(gridList[i].transform.position.z == temp.transform.position.z && (gridList[i].transform.position.x == temp.transform.position.x + 1)){
                 string inName;
                 inName = gridList[i].name;
                 gameObject.SendMessage("RecInnerName", inName);
             }
         }
     }

Can anyone suggest a better approach to this?

Thanks

Comment
Add comment · Show 2
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 robertbu · May 07, 2013 at 04:41 PM 0
Share

A picture would be helpful. Are you talking about a rectangular grid? For ring are you referring to neighbors?

avatar image Renoclaf · May 07, 2013 at 05:15 PM 0
Share

alt text

Hey thanks for replying, here is an image of what its like so far. I labeled 1,2,3 to show what I mean by rings.

tiles.jpg (64.7 kB)

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

12 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 avatar image avatar image

Related Questions

Targeting multiple tiles in grid, updating with player movement 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

A node in a childnode? 1 Answer

3D level generator on a grid C# 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