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 Cbjfan1 · May 31, 2013 at 11:42 PM · randomalgorithmgenerated

accessing variables from nearby gameobjects (Prim's Algorithm)

Hey everyone. I'm trying to make a labyrinth with a randomly generated map

like this one: http://www.youtube.com/watch?v=ucWX34Vrel8

I currently have given each point a randomly generated number, but how can I check to see if the number of adjacent points are larger or smaller?

This is what I currently have:

 var number : float;
 
 
 function Start() {
 number = Random.Range(1,255);
 }


Would I need to change var number to a static variable?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by darthbator · May 31, 2013 at 11:52 PM

Are the blocks touching? If they are you can use the collision system. If they're not touching just shoot rays out of all the sides. You can then access the objects off of the hit data. Setting it static would mean that it would be the same across all instances of the class. So if you changed it in one object it would change in all of them. I don't feel like that's what you're after, hence my suggestion to use rays or collisions and then use GetComponent to access the remote var.

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 Cbjfan1 · Jun 01, 2013 at 01:11 AM 0
Share

So far I have this: var number : float;

 function Start() {
 number = Random.Range(1,255);
 }
  
 function Update() {
 var hit : RaycastHit;
 var ray = new Ray (transform.position, transform.forward);
 if (Physics.Raycast (ray, hit, 100.0))
       {
       if(hit.transform.tag == "Cube"){
       var numberscript = hit.transform.GetComponent(RandomNumber);
       var OtherNumber = numberscript.number;
  
 Debug.Log ("Hit Object");
 }
 }
 }

I'm getting an error at var OtherNumber = numberscript.number; that says this:

NullReferenceException: Object reference not set to an instance of an object RandomNumber.Update () (at Assets/Game/RandomNumber.js:15)

avatar image
0

Answer by jerichaosymphony · Jun 01, 2013 at 06:59 AM

Tag all squares/cubes with a word like "square", then do :

 function findclosest(){
 var allsquares = findallwithtag"square";
 for (var square in allsquares){
 if (distance (current square,square)<(diameter of squares*1.5))
 }

(pseudocode) then you have the closest, you can make an array of the gameobjects, then make a new loop that compares the value of centre to all neighbours.

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

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

Related Questions

For Loop isn't working properly! 1 Answer

Algorithm to script 0 Answers

Room generator spawn 1 unique room 1 Answer

A fast triangle triangle intersection algorithm for unity? 4 Answers

pre generated world 0 Answers


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