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 velv · Jun 21, 2012 at 08:25 PM · instantiateobjectclass

Calling an object from a different JS Script and Instantiate it

Hi everyone, I already have House_1 script in which i built a house with columns. Now i need to build another house (script: House_2) in which i 'll put it a few columns too. Instead of copy-paste the same code to build those columns, i prefer to Instantiate the column object by the previous script. try to avoid the same many code lines as i had with the House_1 script.

Here is the main idea:

Class House_1:

 //code
 var oColumn = GameObject.CreatePrimitive(PrimitiveType.Cube);
 oColumn.transform.position = Vector3(RandX -3.2, 1.7840475, RandZ + 3.3772203);
 oColumn.transform.parent = oMainBuilding.transform; //parenting
 oColumn.name = "Column right 0";
 oColumn.transform.localScale.x = 0.05992945;
 oColumn.transform.localScale.y = 0.3776168;
 oColumn.transform.localScale.z = 0.08529133;
 //code

Class House_2 ( i tried 3 options, close to my problem):

(1)

 `var column : House_1 = GetComponent(House_1);
 column.oColumn;`

And got the exception: "'oColumn' is not a member of 'House_1'."

(2)

 `var column: GameObject;
 column = GameObject.Find("House_1/Column right 0");
 column.transform.parent = oMainBuilding.transform; //parenting
 column.transform.position = Vector3(RandX, 1.7840475, RandZ + 3.3772203);
 column.name = "column";
 column.transform.localScale.x = 0.05992945;
 column.transform.localScale.y = 0.3776168;
 column.transform.localScale.z = 0.08529133;`

No exception but i can't see anything.

(3)

 `var columnObj : GameObject;
 var column= GameObject.FindWithTag("House_1/Column right 0");
 columnObj.transform.parent = oMainBuilding.transform; //parenting
 Instantiate(columnObj, column.transform.position, column.transform.rotation);`

And got the exception: "UnityException: Tag: House_1/Column right 0 is not defined! UnityEngine.GameObject.FindWithTag (System.String tag) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/BaseClass.cs:414)"

Anyone knows why? Or know what i can do to see the column in my new House? Thanks in advance.

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 Berenger · Jun 21, 2012 at 09:17 PM

You're not writing your entire code so it's hard to say, but apparently oColumn isn't declared in the correct scope. It should be a member of the class, not a var from the function.

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 velv · Jun 22, 2012 at 10:42 AM 0
Share

How do we gain access from a member of a class? the oColumn is an object created in the House_1 class, and it's a child to o$$anonymous$$ainBuilding: (Class) House_1 { (GameObject) o$$anonymous$$ainBuilding --> (GameObject) oColumn --> (GameObject) oColumn_base --> (GameObject) oColumn_upperpart }

oColumn is not a member of a function nor is a variable. (other languages used to do that to gain access: House_1.oColumn)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity script system 2 Answers

Instantiating a class 1 Answer

Unity return error message like method not a member of Object class 1 Answer

How can I enable an object from a script? 1 Answer

JS Objects VS Class (are they the same?????) 2 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