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 CG-DJ · May 16, 2013 at 12:26 PM · functiontargetorderparameterfirst

Make Unity know which target was hit first.

Ok, I'm stuck here.

I'm making a shooting range mini-game. I have a machine with 4 targets with numbers on them. I randomly generate the order of the numbers 1-4 and have the player shoot the targets in the order that I generate. (Make sense?)

What I need is a way to figure out in what order the player shoots the targets. I need to know which target he hit first, which target he hit second, etc. If there was a way I could make parameters I could send to another function that would tell the function what target was hit, and in which order it was hit, that'd be great. I just have no idea where to start.

Thanks ahead of time!!!

Comment
Add comment · Show 3
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 robertbu · May 16, 2013 at 01:38 PM 1
Share

If you are using C#, take a look at events and delegates:

http://www.indiedb.com/games/coco-blast/tutorials/delegates-events-and-singletons-with-unity3d-c

http://www.youtube.com/watch?v=N2zdw$$anonymous$$IsXJs

Or you can find another game object and communicate directly:

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

avatar image CG-DJ · May 16, 2013 at 01:52 PM 0
Share

Ok, sorry I probably should have said this. I am using UnityScript.

$$anonymous$$y problem doesn't come with trying to access other scripts components, I need to know which target was hit first, which was hit second, etc. I need to know whether or not the player hit the targets in the right order.

avatar image robertbu · May 16, 2013 at 02:43 PM 0
Share

Then I'm having trouble understanding where you are having the problem. For example: you have your tracking script attached to a game object somewhere in the project. All the targets get access to this tracking component. Using a singleton would make this easy, but you can use GameObject.Find() and GetComponent() to get access. Each target has an id as part of the script attached to the target. As each target registers a hit, it reports that id to the tracking script. The tracking script needs to know when a round starts, then it just has to see if the target is the next one in the order. When a round starts, it looks for target 1, if 1 is reported, it looks for 2. If a target comes in that is not one expected, it is out of order.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kristian · May 16, 2013 at 02:03 PM

I assume that you want to check the order. A simple approach would be to give them identifying names i.e. "1", "2", "3" & "4". Then add them to a collected string on hit, and in the end check if the collected string is "1234". It's not the most optimal approach, but it should do the trick if I understood your issue correctly.

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

15 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

Related Questions

How to pass classes of a class to a function's parameter? 1 Answer

Function as parameter? 1 Answer

return value of a function passed to another function as a parameter 0 Answers

How to pass Predicate to a Coroutine? 1 Answer

Why pass parameters into a function? 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