- Home /
Generating script runtime
Hi again. I wonder if it's possible to make script runtime(C# script via C#)? I want to make gun crafting system in my game. It'l be working like all parts will have variables like:
float fireRate = 0.15f;
So this part will 'give' our new weapon +0.15 fire rate.
regards
Paweł
You can make a anonymous object that implements an interface and call it latter, just use it as a getter for this value.
Answer by aldonaletto · May 26, 2013 at 02:31 AM
This question isn't clear, but creating scripts at runtime hardly would be the solution for whatever you want to do. If you want to customize weapons, there are other solutions: you could for instance have a weapon prefab with all the possible accessories childed to it, and activate only the desired ones with gameObject.SetActive. If you want to define properties like fire rate, caliber etc. at runtime, use the GUI system to display buttons and text fields where the player can change these items.
Sorry but you don't understand my logic. I can't make weapon with all things attached and just removing/adding them because I want this work like in Dead Space 3(or better)(Player will have parts from some other guns and can make own gun from them. For ex. 1/2 shotgun - 1/2 Assault rifle. There will be milions of combinations so it's impossible to make all of them). And I want to make new script runtime because i wan't to chceck what part giving what.
I don't know exactly how to create scripts at runtime, but AFA$$anonymous$$ it's possible - and probably very hard to do (follow @FL's clue in the comment above). Anyway, this would not be the solution: a custom weapon is basically a group of models childed together to a base game object, with some specific components (scripts). You can have a "super weapon" with all part models and scripts attached and just activate the selected ones, or a weapon creation script with all parts defined in public arrays, and instantiate the selected ones.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
reimporting at runtime? 0 Answers