Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by jonowtpt · Mar 07, 2019 at 12:03 AM · textscripting beginnershootingpopup

Text popup on target hit

Hi all, first time posting, new to unity. such a great program. Just wondering if I could ask some help, I have created a mathematical shooting game, and need to understand how to create a popup window of text once a target has been shot. I have everything else just this im not quite getting. I have a ray cast bullet (I have followed Jimmy Vegas FPS script for this) and target disappears once hit, not a problem, however i need to add a script that prompts a popup window with a question, 1+1= is fine at the moment. then user will need to input answer and that will determine if target survives or dies. eventually will need to randomize questions however for the prototype any popup with correct answer should destroy target. any advice or help would be much appreciated, sorry if this is somewhere else in the forums, (I did look but couldnt see), look forward to getting more involved with the community as my scripting skills improve. Thanks.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MasterChameleonGames · Mar 07, 2019 at 05:14 AM

Have the popup window disabled at the start, and when the target is hit, enable it.

Ideally, you would use an event, but since you're just starting out, an easier way would do.

You can use either script as long as it can detect when the target is hit.

Put all the GameObjects that make up the popup under 1 parent, store a reference to that GameObject in the script, and enable it when the target is shot.

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
avatar image
0

Answer by jonowtpt · Mar 08, 2019 at 12:06 AM

Ok thanks for that, yea kinda makes sense, so just to clarify a few things..

  1. is the popup a 2d canvas with a text script attached for randomized questions?

  2. the event would be 'OnDamage' calling for the target to get damage to action said event?

  3. then would need an if statement to validate answer and perform true outcome?

  4. if i have got this correct do i create separate scripts or do i embed code into existing scripts and reference it?

I think i understand what you are saying i am just unsure of best way to execute it. but i do appreciate your response as it has given me some direction on how to research solutions.

Comment
Add comment · Show 5 · 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 MasterChameleonGames · Mar 08, 2019 at 12:59 AM 1
Share
  1. Yes, and you could use the Panel GameObject if you want to make it look more like a popup.

  2. If you want to use an event, the target or bullet script would call the event, and a script on the popup would enable the popup when the event is called. I'd suggest a name like "OnHit".

  3. I'm assu$$anonymous$$g this is about when the player answers the question? Yes, there would need to be an if statement to check if the player is right. If it is free-response, use an input field and call the function on OnEndEdit. Or you could have a submit button. If it is multiple-choice, just use buttons.

  4. You don't have to, you can just store a reference to the popup in an existing script and enable it when you need to ins$$anonymous$$d of using events.

avatar image jonowtpt MasterChameleonGames · Mar 08, 2019 at 04:01 AM 0
Share

Ok that is awesome! yes i understand exactly what you are saying, i just dont have the scripting skills right now to create such code. are you able to advise of anywhere where someone may be able to assist with the scripting. I dont mean to be so forward and ask directly i am just at the end of my ability level. the below code is my simple enemy health script, and my gun damage script, bullet takes 1 hit points, once enemy health =0 i want to call the popup (1+1=_) with player to submit 2 as correct answer.


var EnemyHealth: int = 1;

function DeductPoints(DamageAmount: int) { EnemyHealth -= DamageAmount; }

function Update() { if (EnemyHealth <= 0) { Destroy(gameObject); } }


var DamageAmount: int = 1; var TargetDistance: float; var AllowedRange: float = 15;

function Update() { if (Input.GetButtonDown("Fire1")) {

     var Shot: RaycastHit;
     if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), Shot)) {
         TargetDistance = Shot.distance;
         if (TargetDistance < AllowedRange) {
             Shot.transform.Send$$anonymous$$essage("DeductPoints", DamageAmount);
         }
     }
 }

}


If you are able to advise where/how/what my code should look like regarding the call to pop up i would greatly appreciate it, otherwise you have already been immensely helpful and i thank you for your assistance so far. (i know its a lot to ask). Thanks in advance.

avatar image MasterChameleonGames jonowtpt · Mar 08, 2019 at 04:37 AM 1
Share

At the top, declare a variable that will store a reference to the popup.

public var popup: GameObject; (you can change the name if you'd like, and you can put [ShowInInspector] ins$$anonymous$$d of public, it will have the same effect)

When you save the code and go back to the Editor, you'll see the variable show up in the Inspector. Drag the popup GameObject over to the box beside the variable's name, and now the code has a reference to it.

Inside the if(EnemyHealth

popup.SetActive(true).

This will make it so that the popup will appear when the enemy is out of health.

Also, if you're looking for tutorials, I'd recommend the official ones, they explain everything the best.

Show more comments

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

111 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 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 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 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 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 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 would I script text to pop up? 1 Answer

I can't make my player to shoot faster (Check script for reference) 1 Answer

Pass values between texts,Can't pass the value to the Game Over panel 0 Answers

Problem with a charged projectile direction 1 Answer

How to make text pop up for a few seconds? 3 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