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 MI_Inc · Apr 30, 2020 at 08:50 AM · damagesendmessagecombat

I have a problem inflicting damage to my enemies... It works when using it without an array but as soon as I I do put them in it gives me a "MissingMethodExpection"... Here is the code

//This is damage function

[SerializeField] private float maxHealth, knockBackSpeedX, knockBackSpeedY, knockBackDuration, knockBackDeathSpeedX, knockBackDeathSpeedY, deathTorque;

 [SerializeField]
 private bool applyKnockBack;
 [SerializeField]
 private GameObject hitParticle;
     

 private float
     currentHealth,
     knockBackStart;

 private int playerFacingDirection;

 private bool 
     playerOnLeft,
     knockBack;

 
 private PlayerMovement pc;

 private GameObject
     aliveGO,
     brokenTopGO,
     brokenBotGO;

 private Rigidbody2D
     rbAlive,
     rbBrokenTop,
     rbBrokenBot;

 private Animator aliveAnim;

 private void Start()
 {
     currentHealth = maxHealth;

     pc = GameObject.Find("Player").GetComponent<PlayerMovement>();

     aliveGO = transform.Find("Alive").gameObject;
     brokenTopGO = transform.Find("Broken Top").gameObject;
     brokenBotGO = transform.Find("Broken Bottom").gameObject;

     aliveAnim = aliveGO.GetComponent<Animator>();
     rbAlive = aliveGO.GetComponent<Rigidbody2D>();
     rbBrokenTop = brokenTopGO.GetComponent<Rigidbody2D>();
     rbBrokenBot = brokenBotGO.GetComponent<Rigidbody2D>();

     
     aliveGO.SetActive(true);
     brokenTopGO.SetActive(false);
     brokenBotGO.SetActive(false);
    
 }

 private void Update()
 {
     CheckKnockBack();
 }

 public void Damage(float details)
 {
     currentHealth -= details;

     if (details < aliveGO.transform.position.x)
     {
         playerFacingDirection = 1;
     }
     else
     {
         playerFacingDirection = -1;
     }

     Instantiate(hitParticle, aliveGO.transform.position, Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)));

     if (playerFacingDirection == 1)
     {
         playerOnLeft = true;
     }
     else
     {
         playerOnLeft = false;
     }

     aliveAnim.SetBool("playerOnLeft", playerOnLeft);
     aliveAnim.SetTrigger("damage");

     if (applyKnockBack && currentHealth > 0.0f)
     {
         KnockBack();
     }

     if (currentHealth <= 0.0f)
     {
         Die();
     }
     
 }

 private void KnockBack()
 {
     knockBack = true;
     knockBackStart = Time.time;
     rbAlive.velocity = new Vector2(knockBackSpeedX * playerFacingDirection, knockBackSpeedY);
 }

 private void CheckKnockBack()
 {
     if (Time.time >= knockBackStart + knockBackDuration && knockBack)
     {
         knockBack = false;
         rbAlive.velocity = new Vector2(0.0f, rbAlive.velocity.y);
     }
 }

 private void Die()
 {
     aliveGO.SetActive(false);
     brokenTopGO.SetActive(true);
     brokenBotGO.SetActive(true);

     brokenTopGO.transform.position = aliveGO.transform.position;
     brokenBotGO.transform.position = aliveGO.transform.position;

     rbBrokenBot.velocity = new Vector2(knockBackSpeedX * playerFacingDirection, knockBackSpeedY);
     rbBrokenTop.velocity = new Vector2(knockBackDeathSpeedX * playerFacingDirection, knockBackDeathSpeedY);

     rbBrokenTop.AddTorque(deathTorque * -playerFacingDirection, ForceMode2D.Impulse);

     
 }

//This is in combat damage script

private void CheckAttackHitBox() { Collider2D[] dectectedObjects = Physics2D.OverlapCircleAll(attack1HitBoxPos.position, attack1Radius, whatIsDamagable);

     foreach (Collider2D collider in dectectedObjects)
     {
         collider.transform.parent.SendMessageUpwards("Damage", attack1Damage);
         //Instantiate hit particle
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

126 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

Related Questions

Child object collision 2 Answers

Trigger and ennemy damage 2 Answers

Need help implementing a damage reduction 1 Answer

Need A Combat System. 0 Answers

Multiplayer do damage 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