Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
Aeleas

Define target by tag and search for child inside it ?

Question

Hi. I'm working on Tower Defense game. My character follow my mouse click on the map scene and if there are any enemies near him he aims directly at him.

I copy most of the script from YT tutorial and I adjust it. I need help with two things here:

1/ line 6. target here is one enemy. What if I have more than 3 enemies ? How to make target is any object with "enemy" tag ?

2/ line 86. If my character selected target. I need to search for child object inside this target call "dead_point" ?

Please login or register to see this link.

 

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 1

1:

 

targets = GameObject.FindGameObjectsWithTag("Enemy");

target = targets[someValue];

 

2:

 

deadPoint = target.transform.Find("dead_point");

  • Like 1

Share this post


Link to post
Share on other sites

  • 0

Thank you for you respond.

Second point solved. :)

first point still need to rechecked. Because I didn't test yet. 

you mean something like this:

Please login or register to see this code.

 

Share this post


Link to post
Share on other sites
  • 0

Ya something like that. Just try not to use find methods in an update loop. You can either add it to a list every time an enemy is spawned and remove it on the death function or you can use a find function in the start function and every time an ai dies or spawns, use the find method again

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...