- Home /
GameObject.name to call script name?
Hi guys, im implementing pragma strict and now need to get rid of my dynamic scripting (?)
Anyways my old script did this.
var FObject : GameObject;
//FObject is instantiated within the script first, from resources
function Update () {
FObject.GetComponent(FObject.name).FWild = 1;
}
The script name of the object is the same as the object itself, and therefore wanted to reference it's script by just calling the object's name. So how can i solve this in a way which is acceptable with pragma strict?
Error: BCE0019
Thanks!!
Answer by Yword · Jan 22, 2014 at 09:44 AM
I think you need to cast the component to the type of the component first.
var component : TypeOfComponent = FObject.GetComponent(FObject.name) as TypeOfComponent;
component.FWild = 1;
Hey thanks for the reply
Im assu$$anonymous$$g im supposed to fill in typeofcomponent, but i dont know what with. Im pretty new to this.
It's supposed to be a script.
Thanks for your trouble, but i've decided to overhaul my scripting system to accommodate non-dynamic scripting, and so for now, my problems are solved.
Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220613131109im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Create Array Accessible By Any Script 2 Answers
Trying to access gameobject variables 0 Answers
how do i change a bool from another script 1 Answer
Access UI in scene from an instance prefab 1 Answer
Restart button 7 Answers