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 joseph b · May 09, 2011 at 02:57 PM · runtime-error

small script problem

public var curwp : Transform; public var open : Transform[]; var bestrate: float = 10000; var val : Transform; function Start () { var open = GetComponentsInChildren.<Transform>(); }

function LateUpdate () { bestrate = 10000; //print ("q"); for (var val : Transform in open){ <------ hear print ("a"); var ratesorce = val.GetComponent ("score"); if (ratesorce.ttlscr < bestrate){ bestrate = ratesorce.ttlscr; print (bestrate); } } }

ime doing a script for path finding and it works without error message however it dose not print or do anything past the marked place

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
0

Answer by sneftel · May 09, 2011 at 03:12 PM

By using var open in Start you're redeclaring open as a local variable, rather than using the open declared in your behavior.

Comment
Add comment · Show 2 · 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 joseph b · May 09, 2011 at 03:17 PM 0
Share

k tx i now have a problem with the if statement. (ratestore.ttlscore < bestrate)

and comes up with a mesige object reference not set any solution ??

avatar image sneftel · May 09, 2011 at 03:42 PM 0
Share

I couldn't understand any of that. $$anonymous$$aybe you could use real words and sentences?

avatar image
0

Answer by Bunny83 · May 09, 2011 at 04:14 PM

First of all, don't post the same question 3 times!

Second, Sneftel told you what you've done wrong, but it seems you don't have a clue what he's talking about. That's a basic logical error. You should learn some basics about programming and the scope of variables.

open is declared as public variable in your script, but in Start you declare a new local variable also called open. You want to assign the result of GetComponentsInChildren to your public variable so remove the var keyword inside Start.

It seems the same goes for your val variable. In this case you just need the local variable that is declared inside your for-loop.

public var curwp : Transform; public var open : Transform[]; var bestrate: float = 10000;

function Start () { open = GetComponentsInChildren.<Transform>(); }

function LateUpdate () { bestrate = 10000; //print ("q"); for (var val : Transform in open){ print ("a"); var ratesorce = val.GetComponent ("score"); if (ratesorce.ttlscr < bestrate){ bestrate = ratesorce.ttlscr; print (bestrate); } } }

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

No one has followed this question yet.

Related Questions

Random Invalid AABB inAABB error 2 Answers

Unidentified error 3 Answers

GameObjects missing from compiled game 1 Answer

ExecutionEngineException: Attempting to JIT compile method 0 Answers

Error while using Facebook sdk and google Admob ad plugin 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