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 Kusho · Nov 26, 2013 at 04:30 AM · enemyspawntextmesh

Unity messing TextMesh related variables?

I have a enemy spawner that spawns an enemy every 5 seconds.

Enemies have a 10-hit health bar, made from a TextMesh and converting an array to string, and then attaching it to the "Text" variable of TextMesh.

It works fine with one enemy on scene, but, if another enemy spawns (that's why i increased the health bar) something extrange occurs. I will explain it by points:

  1. Enemy(1) spawns. 10HP

  2. Enemy(1) moves towards destination (using unity's pathfinding) while recieving hits from tower.

  3. Enemy(1) has 3HP, spawner interval reaches 0;

  4. Enemy(2) spawns with 10HP, but no health bar. Enemy(1) gets Enemy(2) health bar, but it does not update (remains on 10 HP);

  5. Enemy(1) is destroyed since the health variables are ok (went from 3 to 0).

  6. Enemy(2) gets back its health bar and everything works fine until...

  7. Enemy(3) spawns and all process start again.

Since i'm working on JavaScript, this is the health bar making:

 function Update(){

 var tm : TextMesh = GameObject.Find("Health").GetComponent(TextMesh);

 var healthArray = new Array();

 for(i=0;i<currentHealth;i++){
     healthArray[i]="-";
 }
 
 healthString= Array(healthArray).Join("");
 
 tm.text = healthString;    
 tm.renderer.material.color = Color.red;
 tm.transform.forward = Camera.main.transform.forward;

 .....

I think that the problem is the TextMesh reference, which is getting the wrong one to operate, but i'm not sure at all.

Comment
Add comment · Show 2
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 rutter · Nov 26, 2013 at 05:44 AM 0
Share

GameObject.Find() simply returns the first matching object in the scene. Do you have a unique Text$$anonymous$$esh attached to each enemy? If so, you should probably find that particular enemy's Text$$anonymous$$esh ins$$anonymous$$d of searching the entire scene.

avatar image Kusho · Nov 26, 2013 at 01:51 PM 0
Share

Actually the Text$$anonymous$$esh which is called "Health" is part of the enemy prefab. Enemy prefab is composed by a model taken from Angry Bots (parent object) and then the "Health" Text$$anonymous$$esh(children of the model).

I've tried GetComponentInChildren, but i does not work (it does the same). Now you said that about .Find(), i think that might be the problem. Since i call it every update, it will take the first enemy spawned.

How i can manage that?

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

Enemy Spawning Place 0 Answers

Enemy not spawning correctly 1 Answer

More Efficient Enemy Spawning Than This? 2 Answers

Make enemies spawn faster with timer? (C#) 2 Answers

Spawning enemies randomly without collisions 3 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