- Home /
more pragma strict getComponent and SendMessage problems
I have a many game objects with many scripts attached during runtime. The user chooses which script to attach to which gameObject.
Without pragma strict I change properties and run functions on those scripts from the main script and it works fine. With pragma strict nothing works.
Here's what I've tried so far and the errors I get with
#pragma strict;
function changeSomething(go:GameObject,script:String){
go.GetComponent(script).initialize();//doesn't work
var prop=go.GetComponent(script).somepropertyinscript; //does not work either.
go.SendMessage("initialize"); //works
var test=go.SendMessage("getProperty"); //doesn't work
}
SendMessage cannot return a value???
Right now nothing works..I could make a different function for every possible combo of gameObject and script but that may be 50 functions if I have 5 gameobjects and 4 script choices each? Or I could move everything into one script?
Is there a better way to go about talking to scripts with pragma strict?
Thanks,
that might compile without strict, but it would not actually work as intended. Send$$anonymous$$essage returns void.
Your answer
![](https://koobas.hobune.stream/wayback/20220613064606im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
pickup weapon with GetComponent 0 Answers
GetComponent for all enemies 1 Answer
Best way to access variables of script from granchild of another object, into a different script? 1 Answer
Move a cube from GUITexture. Is not working. Where is my mistake 0 Answers
How would I do SendMessage to a specific component on the same object? 2 Answers