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 oinkoinkflapflap · Jul 29, 2012 at 05:26 PM · gameobjectinstantiatetransformvariablestatic

static gameobject

i have a script on one object, the script is called "Manager"

 static var share : GameObject;
 var obj : GameObject

 function Update () {
       share = obj
 }

then another script on another object to instantiate.

 var object : GameObject;

 var spawn = Instantiate(object ,Manager.share.transform.position,Quaternion.identity);
 object.transform.parent = Manager.share.transform;

but it doesn't seem to work :/ any ideas? thanks

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 oinkoinkflapflap · Jul 29, 2012 at 05:29 PM 0
Share

i'll add the object with the second script is instantiated at runtime itself and the "share" object is in the scene from the start as is the object containing the first script

thanks

avatar image ScroodgeM · Jul 29, 2012 at 05:36 PM 0
Share

check for null '$$anonymous$$anager.share' before instantiating.

and... what does it mean - 'doesn't see to work'?

avatar image Seth-Bergman · Jul 29, 2012 at 05:41 PM 0
Share

how are you calling the Instantiate? is that inside a function?

avatar image peterpunk · Feb 03, 2016 at 09:04 AM 0
Share

The relationship between a static property which is a gameObject is a non trivial matter, I wrote some extended notes here.

1 Reply

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

Answer by fafase · Jul 29, 2012 at 05:36 PM

A static game object? Just search and find the object. Here I assume the GO is named Share:

 var object : GameObject;
 var share:Transform;
 
 function Start(){
 share = GameObject.Find("Share").transform;
 }
 
 var spawn = Instantiate(object ,share.transform.position,Quaternion.identity);
 object.transform.parent = share.transform;
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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get the Vector position of the player object when clicking another object C# 1 Answer

How to make random alien fire and not all of them at once.. 2 Answers

Set parent of instantiated object. 0 Answers

How to instanciate transform to element of a list?,How Get Transform of a instanciated Prefap 3 Answers

problems parenting a gameObject to another upon instantiating when same name exists 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