Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Tom de Jank · Feb 02, 2010 at 04:32 PM · transformarrays

transform array in javascript

hi there, this is tom again. after finishing my last project with some helpfull hints from the folks out here, I started a new project with new problems. I build a little plaza and a seeker drone should move between some points. for that I use the "SeekSteer" script from the unity Wiki pages. it works very fine when I use a drone in normal way. the script defines the destination points in an array in form of JAVASCRIPT "var waypoints : Transform[]". when I change the seeker object to a prefab, then it looses all the preset waypoints and i cant set them. do anybody has experience with that script or can tell me how to define the waypopints within the script in an form like:

waypoint[0] = Transform p1, waypoint[1] = Transform p2, waypoint[2] = Transform p3,

... thx a lot from berlin tom

Comment
Add comment · Show 4
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 duck ♦♦ · Feb 02, 2010 at 04:34 PM 0
Share

What are "p1", "p2" and "p3"? are they the names of GameObjects?

avatar image Tom de Jank · Feb 02, 2010 at 04:57 PM 0
Share

hi duck. yes p1, p2 ... are the names of the GameObjects. this are emty objects

avatar image Tom de Jank · Feb 02, 2010 at 05:16 PM 0
Share

one more time lots of thanks duck. nest time we have a beer...

avatar image duck ♦♦ · Feb 02, 2010 at 06:36 PM 0
Share

no problem :) if it solved your question, please click the 'accept' button.

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by duck · Feb 02, 2010 at 05:12 PM

To build a list of those object's transforms at runtime, you could use something like this (if you know the number of waypoints in advance):

// in c# Transform[] waypoints = new Transform[10];

void Start() { for (int n=0; n < waypoints.Length; ++n) { waypoints[n] = GameObject.Find("p"+(n+1)).transform; } }

// or in Javascript var waypoints : Transform[] = new Transform[10];

function Start() { for (var n=0; n < waypoints.Length; ++n) { waypoints[n] = GameObject.Find("p"+(n+1)).transform; } }

Notes:

  • Set the number of waypoints in the line which declares the array (10, in the example above)
  • The gameObject lookup is case sensitive, so it will find objects called "p1" to "p10", but not "P1".
  • I didn't add code which checks the existence of the objects, so if one of the gameobjects does not exist or is mis-named, you'll get a null reference error.

If you have numerous scenes or situtaions where the number of waypoints might vary, you could modify this code to dynamically discover the number of waypoint objects first, before building the array. That way you wouldn't have to have a hard-coded number in your script which determines the number of waypoints.

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
avatar image
0
Wiki

Answer by irshad khan · May 04, 2010 at 05:30 AM

Plae new java script send me my Email iD

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Conceptual Question on Creating Arrays at Runtime 1 Answer

I have never seen a null reference exception like this one! 1 Answer

NullReference when accessing GameObject in array (C#) 1 Answer

I need to know how to rotate a gameobject in all directions. 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