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 chartreusemango · Nov 27, 2013 at 02:34 AM · javascriptarrayvector3itween

Accessing Vector3s of GameObjects in Arrays (JS)

Hello,

I'm having trouble accessing the transform and rotational data of nodes stored in a Javascript array. I either can't find the proper syntax, or am approaching the problem incorrectly.

This script finds all of the camera nodes (by tag 'Camera Node') and stores them in an array. It then attempts to access the transforms of those GameObjects so that it can move the camera to them.

My code (JS): // VARIABLES FOR CAMERA NODES var cameraNodes = new Array (); var currentCamera : int = 0; var nextCamera : int;

 function Start () {
 
     // Find Nodes
     cameraNodes = GameObject.FindGameObjectsWithTag("CameraPos");
 
 
 }
 
 function MoveNext () {
 
     nextCamera = (currentCamera + 1);

     // Determine if nextCamera is bigger than array
     if (nextCamera > cameraNodes.length) {
     
         nextCamera = 0;
     
     }
 
     Debug.Log("I am going to cameraPosition " + (nextCamera + 1));
     iTween.MoveTo(gameObject,(cameraNodes[nextCamera].Vector3),2);
     
     currentCamera = nextCamera;
     
 
 }

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

1 Reply

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

Answer by robertbu · Nov 27, 2013 at 02:41 AM

A few changes here. First, declare 'cameraNodes' as:

 var cameraNodes : GameObject[];

You don't need to initialize an array for 'cameraNodes' since FindGameObjectsWithTag() returns an array. Plus if you need a collection for a list of game objects, use the .NET generic List class rather than the Array class.

Then on line 21, you can access the nodes as 'cameraNodes[nextCamera].transform.position'

 iTween.MoveTo(gameObject,cameraNodes[nextCamera].transform.position, 2.0);
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 chartreusemango · Nov 27, 2013 at 03:42 AM 0
Share

That works perfectly, thank you!

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

How do I make an array of vectors? 1 Answer

How do you get iTween to properly implement PutOnPath command? 1 Answer

Avoiding instantiating two things in same location? 1 Answer

Javascript - find a value in an array 0 Answers

Array.Push() for Vector3[] or how to add items to Vector3 array without knowing index 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