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 DrunkBearzz · Feb 16, 2015 at 01:44 PM · transformpositionvectortracking

How can I tell my laser which enemy to target?

So this is my problem. It is easy to track position of "specific" gameObject but I have problem while tracking when I have same gameObject in the scene ---> I Instantiante couple enemyes and each one of them Intantiate their own laser who is tracking position of that gameObject...

PROBLEM : if I have one enemy it is fine and laser is folowing position of game object but when having more of them lasers do not know which position they should track becouse there is more than one enemy on the screen.

I hope I explained everything fine and thanks for help.

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 chariot · Feb 16, 2015 at 01:55 PM 0
Share

Create new parameter ("ID", for example) in gameObject and laser In spawner object before instantiates new object set each time new ID (just increment it). Then in laser script check ID of laser and gameObject, if it equals - track, if not - dont track.

 // gameObj script
 
 public var ID : int;
 
 // ur code here

 // spawner object script
 
 public var Prefab : GameObject;
 public var PrefScr : NameOfPrefabScript; // name of script with id attached to prefab
 public var action : bool; // trigger
 public var ID : int;
 
 function Start () {
    PrefScr = Prefab.GetComponent(NameOfPrefabScript);
 
 function Update () {
    if (action){ // if trigger set on
       PrefScr.ID = ID;
       Instantiate (Prefab, transform.position, transform.rotation);
       ID++;
       action = false; // set trigger off
    }
 }


 // laser object script. i dont know how u create laser for new game objects, get ID like in gameObj/spawner for this too.
 
 public var ID : int;
 public var parent : GameObject;
 public var parentScr : NameOfPrefabScript;
 
 function Start () {
    parentScr = parent.GetComponent(NameOfPrefabScript);
 
 function Update () {
    if (ID == parentScr.ID){
        // do what u want, track position and etc.
    }
 }
avatar image Nerzid · Feb 16, 2015 at 01:56 PM 0
Share

Could you tell us what you are trying to achieve ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ben-Stoneman · Feb 16, 2015 at 01:52 PM

You need a way of distinguishing the enemy you need to target.

This question is not a general question on how do I track a GameObject, but instead the question is "How can I tell my laser which enemy to target?". The answer of course is up to your designer it depends on what enemy you want too target, the one closest?

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 DrunkBearzz · Feb 16, 2015 at 05:05 PM 0
Share

Thanks guys, I'm using c# but logic shouldn't be that different but yea I can see what you were going for. Thanks again.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to transform ARFace with Arsessionorigin? 0 Answers

How to edit one axis of the transform position 1 Answer

Unity3D - Playback object array of position (with dynamic velocity) 0 Answers

How to make cubes between 2 point and stick them together? 0 Answers

transform position vectorially 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