- Home /
How to start a boss fight???
Hello, I have a Boss fight which I want to start when my character crosses a specific invisible Box Collider 2D I created on the map. I also created a State animation with default for the Boss to not do anything until it passes. However I do not know how to write the script so that it passes from Default State to actually the entry state of the Boss. I have a base Script: "
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class EnterTheBoss : MonoBehaviour { void OnTriggerStay2D(Collider2D other) { HealthPlayer controller = other.GetComponent();
if (controller != null)
{
}
}
}
Answer by Link17x · Mar 14, 2020 at 09:43 PM
The fight can be triggered in lots of ways...
Some sort of collision/trigger when the player enters a region or enemy radius?
Check the distance between the player and the boss using Vector3.Distance, then trigger something when the player is within a certain range?
When a fight is started in general, call a method to check whether the enemy is a boss. In your enemy script you could use a bool or enum to determine whether it is an enemy or specific enemy type?
I'm not sure exactly what you are trying to achieve, what should happen during a boss fight? Do you want a new fight scene to be loaded, or just trigger some sound effect/visual to alert the player it is a boss etc?
I was trying to go for a collision/trigger when the player enters the region, I already have the entire scripts for the boss and the character, just need to know how to trigger the start of the animations when he collides with the box collider.
Just do something like
private Animator m_Anim;
private void Start()
{
m_Anim = GetComponent<Animator>();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player") // $$anonymous$$ake sure your player has a tag "Player"
return;
// Play your animations
// m_Anim.SetBool or m_Anim.SetInt etc
}
Your answer
Follow this Question
Related Questions
OnTriggerEnter2D(Collider2D other) 2 Answers
Play 2D animations via trigger parameters 1 Answer
Play and Stop Animation 1 Answer
Starting a 2D animation on a trigger 1 Answer
Activate Trigger enable component doesn't work (2d mode.) 1 Answer