• 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 10, 2021 at 04:53 PM · staticdamagemanager

Deal damage (damage_manager)

Hi guys! I have problem with my damage_manager script, he should receive information from a opponent script. unfortunately I don't know where Im doing wrong. Im attaching two scripts. Manager script:

  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 FixedUpdate()
      {
          //if (health <= 0)
          //{
          //    Destroy(gameObject);
          //}
      }
      void OnCollisionEnter(Collision hit)
      {
          player_mechanics stats = GetComponent<player_mechanics>();
          if (hit.gameObject.tag == "Enemy")
          {
              armor_dmg = damage * 0.7f;
              health_dmg = damage * 0.3f;
              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;
              }
          }
  
  
      }
  }

This is the second script where i want to set damage:

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class damage_test : MonoBehaviour
  {
      public float Damage_value;
  
      private void Update()
      {
          damage_manager.damage = Damage_value;
      }

The end result should be that each damage script should send its own damage information to the manager script. Thank you for any help :)

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 Robb_oates · Aug 08, 2021 at 08:24 AM

i think you need to declare the damage manager script with either "getcomponent" or set it in the inspector. and they both will send but the first one to send will be overwritten by the second as you only have 1 variable.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

157 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

Related Questions

Damage manager (ThirdPersonShooter) 1 Answer

Timer System in GameManager with two lists 0 Answers

Static Array JS 0 Answers

Static Collider.Move warning is still in place: should I add Rigidbody or not? (Unity 5.3.3f1) 0 Answers

Trying to set scene object variables in MenuItem editor script and start playing 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