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 bcao · May 08, 2014 at 06:39 PM · textlistgetcomponent

Writing data from multiple instances of a script to text

Hello, i have multiple instances of a script called TransformExtractor running on separate game objects, This script return transform data and mass for a object it is attached to. I need to write the Transform data and Mass to a text file off all instances of the script running and assign each one a key ( starting at 1 ?). What is the simplest way of going about this?

Thanks in advance, Bob

using UnityEngine; using System.Collections; using System.IO; public class TransformExtractor : MonoBehaviour { public GameObject player; public float x; public float y; public float z; public float Qx; public float Qy; public float Qz; public float Qw; public float scaleX; public float scaleY; public float scaleZ; public float Mass; // Use this for initialization void Update () { player = this.gameObject; x = player.transform.position.x; y = player.transform.position.y; z = player.transform.position.z; Qx = player.transform.rotation.x; Qy = player.transform.rotation.y; Qz = player.transform.rotation.z; Qw = player.transform.rotation.w; scaleX = player.transform.localScale.x; scaleY = player.transform.localScale.y; scaleZ = player.transform.localScale.z; } }

This is what i have so far, but it return nothing, when the button i made in the editor is pressed. From the Debug.Log, the function is being called but the Length of transformExtractor is 0.

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Collections.Generic;
 
 public class KS_ObjectInfoGetter : MonoBehaviour
 
 {
     public TransformExtractor[] transformExtractors;
     
 
     public void KSprint ()
     {
         Debug.Log ("KSprint Called");
         Debug.Log (transformExtractors.Length);
 
         transformExtractors = GetComponents<TransformExtractor> ();
         int i; 
         for(i = 1; i < transformExtractors.Length ; i++)
         {
             Debug.Log(i.ToString () + "," +
                       transformExtractors [i].x.ToString () + "," +
                       transformExtractors [i].y.ToString () + "," +
                       transformExtractors [i].z.ToString () + "," +
                       transformExtractors [i].Qx.ToString () + "," +
                       transformExtractors [i].Qy.ToString () + "," +
                       transformExtractors [i].Qz.ToString () + "," +
                       transformExtractors [i].scaleX.ToString () + "," +
                       transformExtractors [i].scaleY.ToString () + "," +
                       transformExtractors [i].scaleZ.ToString () + "," +
                       transformExtractors [i].Mass.ToString () + "," 
 
                       );
         }
     }
 }
 
 
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

Answer by Jeff-Kesselman · May 09, 2014 at 12:04 AM

Assign each instance a unique value by using a static counter.

 public class MySerialnumberedClass: MonoBehaviour{
     static int LastID=0;
     int myID;
 
     void Start (){
        myID = LastID++;
     }
 }
     
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 bcao · May 09, 2014 at 05:11 PM 0
Share

once i add a 'identifier' number to each instance how do i find all the instances and write them to a list?

thanks for the reply

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

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

Related Questions

A node in a childnode? 1 Answer

Get variable from Script in list and , set direct link to other script 1 Answer

Access specific Text among multiple children 0 Answers

Display strings from a list in a text box 1 Answer

GetComponent for gameobject list alternative 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