- Home /
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...
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
This question is from 2 years ago :)..
Thanks anyway :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613083724im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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