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 legion_44 · May 26, 2013 at 02:16 AM · c#runtimegenerate

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ł

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 FL · May 26, 2013 at 02:49 AM 0
Share

You can make a anonymous object that implements an interface and call it latter, just use it as a getter for this value.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 2 · 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 legion_44 · May 27, 2013 at 02:51 PM 0
Share

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.

avatar image aldonaletto · May 30, 2013 at 01:43 PM 0
Share

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

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

14 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 avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

reimporting at runtime? 0 Answers

Export objects to a .3DS file at runtime 1 Answer

Activate a particle system on click c# script 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