- Home /
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
Your answer
Follow this Question
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