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 /
  • Help Room /
avatar image
0
Question by MochaMessiah · Sep 10, 2012 at 10:37 AM · array listenemyshealth bar

Multiple Enemies With Multiple Health Bars.

So right now I have 5 enemies in my game and I have an array with them in it for randomized positions. This is all C# scripts by the way. Since I have multiple enemies I am wondering how I can give each enemy their own health bar and variables/values so when I melee attack them their health and bars decrease separately. Before I had 5 enemies I could attack them and they would be damaged but now that I have 5 enemies I can't even hurt them. Please help!

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 potchieley · Nov 17, 2016 at 03:01 PM 0
Share

EnemyLame does not denote a valid type. How to solve this?

2 Replies

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

Answer by Fattie · Sep 10, 2012 at 11:07 AM

in the actual editor, look at your Hierarchy

try to actually ADD the health bar system, underneath your enemy thing.

ideally, you should just have the one enemy (it's like the "perfect model enemy")

then to make your five, when the game begins, use instantiate to make five of them!!

when you approach life like this you can just add ANYTHING to the "model enemy" when you're working. then ........ it will automatically do that for all of the enemies. awesome.

for instance if you need to add a "green flashing light" just go ahead and add it to your one "model enemy". when you instantiate the five of them in to the array - you make five copies of your "model" enemy - there you go, they all have green flashing lights.

in this way it will be super-easy to add the health bars (or, anything else).

here's a little bit of code that takes your "model" enemy and makes a dozen of him in an array. but you can do it any way you wish. here, the array holds the actually SCRIPT attached to your enemy - it could just be the transform if you prefer. (PS once you get going, never use an array, actually use a List!)

 ///////////////////////////////////////////////////////////
 
 private var model:Transform;
 // just connect that to your model somehow...
 
 private var ee:EnemyLame[];
 
 function Start()
     {
     ee = new EnemyLame[12]; // the script on the enemy is called 'EnemyLame'
     
     for ( var i:int=1; i<=11; ++i )
         {
         var newy:GameObject = Instantiate( model.gameObject );
         
         newy.transform.parent = transform;
         newy.transform.localPosition = Vector3.zero;
         
         var rr:float;
         
         rr=Random.Range(-3.0,3.0);
         newy.transform.localPosition.x += rr;
         
         rr=Random.Range(-3.0,3.0);
         newy.transform.localPosition.y += rr;
         
         newy.name = "ES" + i;
         
         ee[i] = newy.GetComponent(EnemyLame);
         }
     }
 
 ///////////////////////////////////////////////////////////

Comment
Add comment · 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
0

Answer by MochaMessiah · Sep 10, 2012 at 11:22 AM

Holy cow, thanks so much for the response but we have one problem. I am using C# scripts and I can't use JS's. You see, I am only allowed to use C# scripts. Would you happen to have an C# alternative or equal?

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 Fattie · Sep 10, 2012 at 12:53 PM 0
Share

Hi $$anonymous$$ocha, could you TIC$$anonymous$$ and VOTE any/all useful answer to keep the board tidy

I don't like c# so can't help you there !

don't forget the code is almost irrelevant. you need to read what I said about how to do it - putting the "energy bars" UNDER your enemy, and so on

to be honest that code as such won't really help you at all, it's just an example if managing things when they are "under" you.

there would be 1000s example online in c# about how to "instantiaie" have a search

FTR it would be trivial to change it to c#, if you can't do that you gotta work a bit on coding eh ! enjoy your studies !

avatar image MochaMessiah · Sep 10, 2012 at 02:08 PM 0
Share

Thank you for the response.

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

11 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

Related Questions

duplicating enemies not working correctly 1 Answer

How would you tie a keypress to a fill amount? 1 Answer

I'm trying to insert input field text into an arraylist 0 Answers

Hey, im trying to include a cooldown for my enemy attack. At the moment when the player enters the trigger the enemy attacks really fast and doesnt stop . heres my script, can anybody help? 0 Answers

I have a jump scare and I want it to affect my player's health when it activates it and kill my player when health = 0. 0 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