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 instruct9r · Nov 12, 2012 at 02:47 AM · prefabgetcomponentinstanceaccess

Access manually instantiated object

This is pretty weird. I will try to explain it as good as i can...

I have a prefab of an object called myPrefabObj, that have attached script named (prefabObj_JS). Let's say that in the script i have this

 static var isEnabled

  function Start()
      {
         isEnabled = false;
      }

Then i instantiate that prefab 2 times in the scene (By hand NOT by script), so i have 2 objects in the scene, which are instances of the prefab and they both are called "myPrefabObj".

I have another object called "prefObjController", which have script. In the scipt i write this:

 public var myPrefabTrans : Transform;

 function OnTriggerEnter(col : Collider)
 {
     if (col.gameObject.tag == "Player")
         {
          myPrefabTrans.GetComponent(prefabObj_JS).isEnabled = true;
         }

after that i just insert one of the instantiated "myPrefabObj" objects in the prefObjController's custom created variable.

The problem is that when i trigger the "prefObjController", both instances of the "myPrefabObj" are getting changed their static variable "isEnabled" to true.

I got confused.. I was thinking that if i make custom variable and insert one of the myPrefabObj's into it, i will get controll only on that instance, not on all of them :\

How can i make it, so only the inserted instance of the prefab is getting controlled and NOT all of them in the scene...

Thank you... Thank you...

Comment
Add comment · Show 1
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 revolute · Oct 15, 2014 at 05:02 AM 0
Share

Remove static.

1 Reply

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

Answer by g8minhquan · Oct 15, 2014 at 05:01 AM

 static var isEnabled

Because you use a static var, remove the "static" then it will work as you expected

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 instruct9r · Oct 15, 2014 at 11:49 AM 0
Share

This question is from 2 years ago :)..

Thanks anyway :)

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

10 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

Related Questions

Remove HingeJoint2D from the Instance not from the Prefab 0 Answers

How to get script from Object with (Clone)'s script? 2 Answers

Can't Access Prefab Script from FPS Controller 0 Answers

How to get all instances of an object in the scen 2 Answers

"Object reference not set to an instance of an object" Error 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