Hello, I’ve started trying to replicate the game cuphead, I’m trying to make a boss level like the 3 Vegetables level. At the moment I have 3 phases, where in each phase the boss does a different type of attack. Now I want to have the boss move to a new position when its time for the new phase. In the cuphead level, how I imagined it happening is: Damage boss, Move on to next stage, boss turns inactive (due to it being invisible and colliders disappearing etc), then after amount of time, boss is active again. So I wrote my code like such :
` IEnumerator Move(Vector3 position, float time = 0f)
{
gameObject.SetActive(false);
if (transform.position != position)
{
transform.position = position;
}
yield return new WaitForSeconds(time);
gameObject.SetActive(true);
}`
And it gets called in the void Update()
function like so: if (healthPercent <= 1f) { if (!attack1Started) { attack1Started = true; StartCoroutine(Move(positions[0], 0)); StartCoroutine(Attack1()); } }
However I get an error saying “Coroutine couldnt be started because the gameobject is inactive”.
What would be the correct way of doing this? Would it be better to remove the sprite and disable the colliders so its similarly invisible? Or better way of scripting? For reference here is the boss fight I’m taking about Cuphead: The Root Pack Boss Fight #1 - YouTube