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
1
Question by spit_fyre633 · Jan 16, 2012 at 04:01 PM · collisionturn-based

Infect the blank cubes

I'm working on a "Game" for a university project, and i am not sure how to do my next section.

Currently, there are several cubes in a grid. the first player selects a cube to infect it with their colour (Red for player 1, Blue for player 2). This bit works fine, but what i want is for the cubes around an "infected" cube, to then become infected after player 2 takes their turn.

I'm not sure how to go about this, i tried with collision, and that didn't work. I also thought about doing a sphere cast around the cube, and if there were any red cubes within the sphere, then it would turn red itself. But, i lack the knowledge to do this either.

My question is this, what would be the best way to infect blank cubes, that are next to red (Or Blue) cubes, after both players have taken their turns?

Comment
Add comment · Show 6
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 Eric5h5 · Jan 16, 2012 at 06:36 PM 1
Share

Who downvoted this? It's a reasonable question, and it was even written in clear and comprehensible English. ;)

avatar image icywater · Jan 16, 2012 at 06:41 PM 0
Share

Can you help with this eric? Your the most knowledgeable around here, and no one seems to know the answer. http://answers.unity3d.com/questions/206219/does-using-point-lights-stop-dynamic-batching.html

I supported this question also.

avatar image Owen-Reynolds · Jan 17, 2012 at 04:46 PM 0
Share

What sort of class is it for? What are the goals? Will there be any sort of verbal defense of it, where you have to explain what you did and learned (if so, "I got this code from the internet" is not going to sound good.)

If they haven't covered arrays or OverlapSpheres in class, they probably aren't expecting you to use them. I'd ask your instructor just what sorts of things are expected (what have you covered in class?) and scale it down or change it.

Now, if the goal is to work with 2D arrays, then this is a perfectly good project. I've assigned something similar late in the semester in Program$$anonymous$$g-I classes.

avatar image spit_fyre633 · Jan 17, 2012 at 04:56 PM 0
Share

It is for a $$anonymous$$ultiplayer Online Games Prototyping course. The goals is to be able to rapidly prototype a feature or mechanic to prove it can be done, within a short amount of time. Yes, i will have to explain what i have done, which is why i need to understand it, so i can explain it.

Arrays were covered, briefly, and OverlapSpheres weren't. However, there is no limit on what we can and cannot use. The more the better really.

This would be something i would like to put into a portfolio when done, so whether i can explain it to the lecturer or not when it is done is only important for handing it in as a piece of work, not for the overall outcome. I do consider it a learning curve for myself though, so i would like to be able to learn how to do it anyway.

avatar image Owen-Reynolds · Jan 17, 2012 at 06:03 PM 0
Share

I$$anonymous$$HO, a quick prototype usually involves something you have a pretty good idea how to do, but you need to be sure there isn't some crazy snag. And, you want to get anything working, see if it looks the way you thought it would, and iterate from there.

I'd go with a 1-D array, just to get infection going. You should be able to get more local help (TAs?) with that. The code in an answer below is the right idea. When it runs, I think you'll find some issues: 1) player can only select blank cubes, 2) should infect only blank cubes, 3) off-edge infections crash? 4) ties (blank surrounded by Red/Blue) handled how? 5) It will be difficult to see gamePlay -- should be a delay after each player's move showing infection happening. $$anonymous$$ight be nice to have newly infected squares look different, ....

Again, just my opinion, but rapid prototyping is about ruthlessly scaling down to get anything you can run, test and see what you forgot and need to add. It's about repeating those steps.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Jan 16, 2012 at 04:50 PM

Just use an array that represents the game board, don't bother with collisions and so on.

Comment
Add comment · Show 1 · 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
avatar image spit_fyre633 · Jan 16, 2012 at 04:53 PM 0
Share

Yep, i don't understand what you just said. :P Noob

$$anonymous$$y plan was to instantiate a grid of prefabs of the cube, and just have something that said "if it is next to a red cube, become red myself."...

avatar image
0

Answer by Larry-Dietz · Jan 16, 2012 at 05:41 PM

Here is a quick and dirty example of using Eric5h5's grid suggestion.

This is just an OnGUI demo, and there are more efficient ways of handling it, but this should at least get you started.

When you attach this to an object, (camera maybe in a blank scene) you will get a grid full of G's, Clicking on any of them will change the one clicked, and all of the ones around it to R.

Hope this helps, -Larry

pragma strict

 var grid:String[,] = new String[10,10];
 
 function Start(){
     for(var x=0; x<10; x++){
         for (var y=0; y<10; y++) {
             grid[x,y]="G";
         }            
     }    
 }
    
 function OnGUI(){
     for(var x=0; x<10; x++){
         for (var y=0; y<10; y++) {
             if (GUI.Button(new Rect(x*25,y*25,25,25),grid[x,y])){
                 grid[x,y]="R";
                 if (x>0)
                     grid[x-1,y]="R";
                 if(x<9)
                     grid[x+1,y]="R";
                 if (y>0)
                     grid[x,y-1]="R";
                 if (y<9)
                     grid[x,y+1]="R";
                 if(x>0 && y>0)
                     grid[x-1,y-1]="R";
                 if (x>0 && y<9)
                     grid[x-1,y+1]="R";

                 if(x<9 && y>0)
                     grid[x+1,y-1]="R";
                 if (x<9 && y<9)
                     grid[x+1,y+1]="R";                    
             }
         }
     }            
 }
Comment
Add comment · Show 8 · 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
avatar image Larry-Dietz · Jan 16, 2012 at 05:42 PM 0
Share

Be sure to include the 2 lines above the block, and the 1 line after. Couldnt seem to get the code insertion to work right ;( Still new to this myself ;)

avatar image spit_fyre633 · Jan 16, 2012 at 05:56 PM 0
Share

Yeah, i just copied this into a blank scene, and Unity had a tantrum throwing up a bunch of errors.

avatar image spit_fyre633 · Jan 16, 2012 at 06:02 PM 0
Share

Namely:

http://img710.imageshack.us/img710/5793/captureyfw.png

avatar image Larry-Dietz · Jan 16, 2012 at 06:15 PM 0
Share

Put it in a C# script. Sorry, should have said that up front ;)

avatar image spit_fyre633 · Jan 16, 2012 at 06:19 PM 0
Share

It has to be in Javascript for the assignment.

Show more comments

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

8 People are following this question.

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

Related Questions

Grid based movement collision detection 1 Answer

raycast hit point is wrong 2 Answers

Camera looking through objects when touching 1 Answer

get angular velocity change from collision 0 Answers

No OnCollisionEnter with 2D colliders? 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