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 Defective02 · Nov 02, 2014 at 06:30 PM · gameobjectinspector

Can I add a script into another one to manipulate it's variables in the inspector?

Hello everyone.

I'm quite new with the usage of Unity and i got a slight doubt.

I'm trying to make a game in which a player can step on a mine and get an effect from it, each one with different variables (one effect inflicts damage, another snares..).

So far i had a GameObject with the 'Mine' script on it, and a variable for the effect:

 public class Mine extends MonoBehaviour {
     public var healthTotal : int;
     public var type : ElementEnums.Type;
     public var damage: int;
     public var effect : Effect;
         
     public function Awake() {
         super.Awake();
     }
 
         /*
         code
         */
 }

And the effects extending a common class:

 public class Effect {
     public var duration : int;
     public var texture: CustomTexture;
         
     public function Effect() {
         /*
         code
         */
     }
 
         /*
         code
         */
 }
 
 public class Burn extends Effect{
     public var damage: int;
         
     public function Burn() {
         super();
         /*
         code
         */
     }
 
         /*
         code
         */
 }


With this, in the inspector i can only see the common effect variables alt text

I wanted to make it possible to exchange the effects quickly (dropping in the script same way the a GameObject can be dropped and changing the variables of that script. Kinda like the drop menu of the type).

I've tried it the Effect script extend MonoBehaviour and applying it to a GameObject:

  public class Effect extends MonoBehaviour {
      public var duration : int;
      public var texture: CustomTexture;
          
      public function Effect() {
          /*
          code
          */
      }
  
          /*
          code
          */
  }

This way i can drop each effect in a different object and then drop the object in the mine, but it creates a big ammount of objects in the hierarchy each time that it's triggered the OnEnter event, what i presume that would be bad for the performance the more that it's played :/

I also though of creating different mines, one per effect:

  public class BurnMine extends Mine {
      public var effect : BurnEffect;
  
          /*
          code
          */
  }
 
  public class SnareMine extends Mine {
      public var effect : SnareEffect;
  
          /*
          code
          */
  }
 

But would be a way to do it keeping the generic idea of "create a Mine, drop in the effect wanted" and without relying on GameObjects for the effects?

img.png (8.3 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by sysameca · Nov 02, 2014 at 07:34 PM

If i was coding this i would prefer exactly the second thing you thought - the Mine class to be the base class of all mines and inherit from MonoBehavior - (Mine : MonoBehavior). From there extend it to SnareMine : Mine, FlamingMine : Mine and etc. Then when creating the new mine game object, just assign the type of mine i want it to be. It's very simple and simplicity is your friend. From there all the extended class variables will be shown in the inspector.

Comment
Add comment · Show 1 · 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 Defective02 · Nov 03, 2014 at 06:43 PM 0
Share

I'll go that way then :) thank you for the answer.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Custom Inspector: Targets & GameObjects 1 Answer

Is an object created when dragging a prefab to a GameObject script field 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Loading AssetBundles from inside the Project 1 Answer

Gameover function calling before game ends help 2 Answers


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