Hi!
I am having issues creating a victory music for my game.
I am making a 2d platformer where the main character tries to save her grandma from an evil plant.
What I want to happen is that when the plant boss dies it would stop playing my level music and switch into another soundtrack + open a door to release the granma.
But my unity keeps popping up with 17 error codes and I am confused. I always end up erasing any changes I make because of that.
Here is the script that actually works:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public Animator animator;
public int maxHealth = 100;
int currentHealth;
public GameObject disabler;
// public float attackRange = 0.5f;
// public int attackDamage = 40;
// public Transform attackPoint;
// public LayerMask playerLayers;
//Set health to max health
void Start()
{
currentHealth = maxHealth;
}
//Calculate damage
public void TakeDamage(int damage)
{
currentHealth -= damage;
//Play hurt animation
Debug.Log("Enemy got hit!");
animator.SetTrigger("enemy_hit");
//Kill when health goes under 0
if (currentHealth <= 0)
{
Die();
}
}
//Play death animation and disable enemy
void Die()
{
animator.SetBool("enemy_dead", true);
//Disable enemy
GetComponent().enabled = false;
if (gameObject.tag == "Enemy")
{
Debug.Log("Enemy died!");
GetComponent().enabled = false;
}
if (gameObject.tag == "Boss")
{
Debug.Log("Boss died!");
disabler = GameObject.FindWithTag("BossDisable");
Behaviour[] behaviours = disabler.GetComponentsInChildren();
foreach (var item in behaviours)
{
item.enabled = false;
}
// disabler.GetComponent().enabled = false;
// GameObject[] disableall;
// disableall = GameObject.FindGameObjectsWithTag("BossDisable").SetActive(false);
}
this.enabled = false;
}
// Damage the player
// void Attack()
// {
// //Attack animation
// //animator.SetTrigger("vesimeloni_attack");
//
// Collider2D[] hitPlayer = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, playerLayers);
//
// //Damage the player
// foreach (Collider2D player in hitPlayer)
// {
// Debug.Log("Player got hit!");
// player.GetComponent().TakeDamage(attackDamage);
// }
// }
//Draw sphere to damage collider
// void OnDrawGizmosSelected()
// {
// if (attackPoint == null)
// return;
//
// Gizmos.DrawWireSphere(attackPoint.position, attackRange);
// }
}
**What do I need to add to that to make the changes I want happen?
Any help is appreciated, thank you.**
↧