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 /
  • Help Room /
avatar image
0
Question by Belonek · Feb 12, 2021 at 02:37 PM · floatdamagemanagerreceive

Damage manager (ThirdPersonShooter)

Hi, I have problem with getting value from another script which is in another object. My result right now is almost correct but i done something wrong, cuz damage receives on second tick.

Result below: alt text

Fourth and fifth values ​​are the damage that the enemy deals to the player on collision. I have to fix it in such a way that it detects the damage dealt immediately.

Damage_manager below:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class damage_manager : MonoBehaviour
 {
     //public float health;
     public static float damage;
     private float armor_dmg;
     private float health_dmg;
 
     void Update()
     {
         //if (health <= 0)
         //{
         //    Destroy(gameObject);
         //}
     }
     void OnCollisionEnter(Collision hit)
     {
         armor_dmg = damage * 0.7f;
         health_dmg = damage * 0.3f;
         player_mechanics stats = GetComponent<player_mechanics>();
         if (hit.gameObject.tag == "Enemy")
         {
             Debug.Log(stats.Armor + " " + stats.Health + " " + health_dmg + " " + armor_dmg);
             if (stats.Armor > 0)
             {
                 if (stats.Armor >= armor_dmg)
                 {
                     stats.Armor -= armor_dmg;
                     stats.Health -= health_dmg;
                 }
                 else
                 {
                     stats.Health -= ((armor_dmg - stats.Armor) * 0.5f + health_dmg);
                     stats.Armor = 0;
                 }
             }
             else
             {
                 stats.Health -= damage;
             }
             if (stats.Health < 0)
             {
                 stats.Health = 0;
             }
         }
 
 
     }
 }

I think I am making a mistake in my enemy's script.

Script below:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class damage_test : MonoBehaviour
 {
     public float Damage_value;
 
     private void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.tag == "Player")
         {
             Debug.Log("Sprawdź kolizje - test1");
             damage_manager.damage = Damage_value;
         }
         if (collision == null) { return; }
     }
collision.png (27.5 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AbandonedCrypt · Feb 12, 2021 at 02:56 PM

  1. Class names should never have underscores and should be written in PascalCase (not class_name but ClassName)

  2. variable names should not have underscores, they should be written in camelCase.

  3. I have no idea where you fetch damage_manager from in your 2nd script

  4. Your code in damage_manager only executes when a collision is happening, and it is executed by a collision, so basically a collision makes it wait for a collision to execute code.

  5. You are setting a damage value directly, you should not do this.
    What you could do is:
    implement a method Damage(float damageAmount) that executes the damage logic in DamageManager, and then call that method from the collider (i assume the damage manager works this way, it's all very untransparent)

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

156 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

Related Questions

i cant find an easy way to make damage the same as traveltime 0 Answers

Deal damage (damage_manager) 1 Answer

Best Network Manager Settings For Very Intensive Network ? 0 Answers

background music manager not working correctly 1 Answer

Interesting Script Problem 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