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 MonKcz · Jun 11, 2014 at 09:49 PM · arrayinspectorspawnclassinstance

[SOLVED]How to use attributes from array of custom class instances?

Hey guys, well it seems that I moved on but I dont understand how to access to instances of the class. I will explain.

public Waves[] LevelName = new Waves[3];

This creates 3 instances of class Waves, I can see them in the inspector so it means I can work with them and edit them but what if I want to display the name on the player's screen of first instance (wave) how to approach it ?

alt text

Or if I want to spawn a unit that inherits attributes from wave. e.g. I want to spawn unit that gets hp, armor, movespeed and model from instance (certain wave) and simultaneously display on the screen the name of level (attribute of wave). Is there a way how to do it please?

 using UnityEngine;
 using System.Collections;
 
 public class NewSpawnScript : MonoBehaviour {
 
     public enum ArmorType {unarmored, light, medium, heavy}
 
     [System.Serializable]
     public class Waves {
 
 
         public string waveName;
         public int numberOfUnits;
         public GameObject model;
         public int hp;
         public ArmorType armor;
         public int movespeed;
     }
 
     public Waves[] LevelName = new Waves[3];
 
 }

[EDITED]

Solution was quite simple I was using wrong typed command, thats why it didnt work. For other people usage: e.g.

 Debug.Log(LevelName[IndexOfInstance].armor);

2.jpg (42.7 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

Answer by Jeff-Kesselman · Jun 11, 2014 at 09:51 PM

If you want the instancing to happen s the result of settings in the editor and not at run time, you need to make a custom inspector.

See http://unity3d.com/learn/tutorials/modules/intermediate/editor/building-custom-inspector

and

http://docs.unity3d.com/Manual/ExtendingTheEditor.html

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 MonKcz · Jun 12, 2014 at 07:55 AM 0
Share

I've figured out how to set the size of instances in script or in inspector but now I dont know how to approch them. Please see the edited question above. Btw. thanks for reply :)

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

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

Related Questions

Spawning GameObject from class array Javascript 2 Answers

Public Array with a class not showing in Inspcetor 1 Answer

Array of abstract class in inspector 2 Answers

How to serialize an array of classes 1 Answer

Spawning GameObjects with help of classes --- Attaching classes to GameObjects 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