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 Ryanvanpolen · Jan 17, 2014 at 03:35 PM · tagmultipletargetattacktower-defense

Attack multiple targets in the same tag?

I'm Ryan and I'm going to make a TD game with a Energy tower.

alt text

The problem is that i would like to make a script to attack enemies and I don't know how to attack multiple enemies... Could somebody help me? And I'm a little bit confused so I've to change a lot... Thanks for looking...

Here is my script:

link to script

schermafbeelding 2014-01-17 om 15.59.22.png (76.0 kB)
energytower kopie.txt (780 B)
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 hamstar · Jan 17, 2014 at 05:09 PM 0
Share

Can you confirm how you want it to behave? e.g. attack enemies at exactly the same time (fire multiple shots at once), attack one after the other, attack closest enemy?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Inan-Evin · Jan 17, 2014 at 05:26 PM

Well I can't edit your code directly cause I can have problem with syntaxes. But I can tell you the logic which is better way for you to understand things, always firstly understand the logic. What you need is creating an array, array is a variable of kind which includes multiple variables of definited kinds.

http://docs.unity3d.com/Documentation/ScriptReference/Array.html

You are going to create the array of enemies :

 var myTargets : Transform[];


And you can use array codes to add objects to your array, you can check gameobjects tagged as enemy with this :

 myTargets = GameObject.FindGameObjectsWithTag("Enemy");

// ( there may be a better usage i just wanna give some examples )

by this, you check the gameobjects tagged as enemy, and make them into your array. ( As I said I'm not sure about that, there may be a better way to add objects to your array )

Next thing you wanna do is make your object select random object from enemy array ( you can adjust the "random" like closest or farest, just seek in here to find how to use arrays, a lot of people asks about them )

Then you are gonna make your object to attack the selected enemy in array, for a amount of time, which can be determined or randomed also, then you are going to make your object to select another object in array. Sorry can't give the exact code, just seek in the forums and here. Good luck !

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

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

20 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

Related Questions

How can I target/attack all gameobjects in a certain area? 1 Answer

Multiple Targets Using Tags 1 Answer

Objects with shared tags, delete currently selected? 2 Answers

Find how many are there in the scene 1 Answer

Only damage one object with "Enemy" tag 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