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 Martin_Gonzalez · Dec 13, 2011 at 01:33 AM · loopbulletindexfortower defense

How can i attach a bullet to a tower

i can put several towers in the scene, and they shoot when they are seeing an enemy, my problem is that i have a Checker script in my tower (where i check distance with enemies)and i want to make the bullet follow the enemy that the FOR gaves me. I know that i have to attach my tower to a public gameobject in the bullet so i can Get the component Checker but i cant. the steps are: 1) create tower 2) detect enemy distance - save the enemy index in Checker 3) shoot 4) the bullet following the enemy with the Index saved

Thx!

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 Lo0NuhtiK · Dec 13, 2011 at 03:02 AM 0
Share

Either I'm even more tired than I already think I am, or ...somethin...
You wanting a heat-seeking bullet of a sort, or what?

Edit:
I'm bored, half asleep, and been staring at my computer screen for round-about 12 hours now. Just felt like adding to this comment that my initial thought when I first saw the title of this question was "Duct Tape".

avatar image asafsitner · Dec 13, 2011 at 11:11 AM 0
Share

Are you instantiating the bullet every time, or enabling/disabling it?

If you're instantiating it, you can set the target when instantiating.

Then just lerp between positions.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by haider1515 · Dec 13, 2011 at 04:07 PM

Instantiate the bullet at the tower.position+offset.. define rang say range=5; gameobject target=findtagwith(enemy); if(vector.distance(transform.position,target.postion)

GameObject.LookAt.... give it a tag which you want to follow.. bullet.lookat ( target)..forceon forward

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 asafsitner · Dec 13, 2011 at 11:23 PM 0
Share

Select your code and hit ctrl+$$anonymous$$ or click the Code Sample button (the icon with binary on it) to format your code and make it readable please.

avatar image
0

Answer by Martin_Gonzalez · Dec 14, 2011 at 01:55 AM

I finish using raycast, is not wat i expected, but it works well. Thx everybody!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get number from a variable name 0 Answers

Having Trouble with this For Loop 1 Answer

For loop going based off of Time.deltatime? 1 Answer

Stopping A Loop - Return or Break? 2 Answers

Using for ... var ... in loop to access variable. 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