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
0
Question by davidjusa · Feb 03, 2020 at 04:10 PM · scripting problemhealth

Player health script doesnt work?

Yo. I made a player health script and an enemy bullet script... I have an enemy script and a normal bullet script too and there the damage works perfectly. But for whatever reason the nearly exact same scripts are not working on the enemyBullet and the player scripts, so what i mean is that the player doesnt get damage although he has the proper script... Can somebody help and tell me what is wrong? There are two screenshots attached with the enemyBullet and the player script ;) alt text alt text

healthscript2.png (86.3 kB)
healthscript1.png (67.0 kB)
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 RahulRaman · Feb 03, 2020 at 04:25 PM 0
Share

$$anonymous$$ake sure you have set the correct value for the damage variable in enemyBullet in inspector or set it in runtime if it is instantiated. I suggest you add a default damage value in the code using public int damage = 1;.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mudassirrazi · Feb 03, 2020 at 04:17 PM

Have you set the damage value in the EnemyBullet script in the editor?

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 davidjusa · Feb 03, 2020 at 05:01 PM 0
Share

yes i did :)

avatar image
0

Answer by unity_ek98vnTRplGj8Q · Feb 03, 2020 at 07:06 PM

Careful, you have two different "player" variables in your bullet script, this is never a good idea. Also make sure that your collision layers are correct and that your bullets are actually detecting the collisions. I suggest adding a Debug.Log(hitInfo.gameObject.name) just to make sure the collision is actually being triggered. If its not then likely either your collision layers are off (check under the physics settings to see the collision matrix), or your bullets are traveling too fast to trigger a collision (raycasting between bullet positions is a common way to fix this issue for fast-moving projectiles)

Comment
Add comment · Show 4 · 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 davidjusa · Feb 03, 2020 at 07:15 PM 0
Share

so i tested it (you can see script changes in the screenshots that are attached) and it didnt even showed the name of the player in the console.. $$anonymous$$y player has a collider and the EnemyBullet too. I dont know why it doesnt show that i hit the player :( alt text

alt text

enemybullet81.png (159.5 kB)
avatar image unity_ek98vnTRplGj8Q davidjusa · Feb 03, 2020 at 07:30 PM 0
Share

to clarify, is your player collider a trigger? Using the OnTriggerEnter function will only work if you have the "trigger" box checked on the collider (I think)

avatar image davidjusa unity_ek98vnTRplGj8Q · Feb 03, 2020 at 07:56 PM 0
Share

Jesus im stupid xD I fixed it with checking the trigger box and adding a fire point to the enemy (the point where his projectiles shoot from) and now it works perfectly fine :) Thanks for helping dude :D

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

214 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 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

I am trying to access a variable from another script. 1 Answer

Error: CS0246 Can't access Player Health Script 1 Answer

Need help with burst fire script / adjusting the amount of damage my gun does. 0 Answers

pick item and add health script have problem 1 Answer

Please Help me JAR Path Java HOME Preferences 0 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