- Home /
Im trying to detect if an object is not active,How to do platform appears when the player dies?
I want to do that if the enemy dies then a platform appears. So when i kill the enemy its disables itself and im trying to detect with this code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Puzzle : MonoBehaviour
{
public GameObject Platform;
public GameObject Enemy;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Enemy.activeInHierarchy == false)
Platform.gameObject.SetActive(true);
}
}
Its not working :/
I dont know how to use this website thats why post is bad
Instead of using if(Enemy.activeInHierarchy
Use if(Enemy.SetActive(false)
Not sure if this work didn't check but give it a try
How do you kill your enemy. Do you call Destroy or SetActive?
Do you have any error in the console?
(And no, if(Enemy.SetActive(false)) will definitely NOT work)
Answer by MurphyMurph_21 · Nov 17, 2020 at 09:24 AM
Im pretty sure checking for activeself is better than activein Hiearchy.
if(Enemy.activeSelf == false)
{
Platform.gameObject.SetActive(true);
}
I didn't even notice someone replies but thanks ig. I was dumb as heck back then.
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Does inactive Objects eat up Performance? 1 Answer
How to make a gameObject disappear when a mouse hovers and reappear when the mouse leaves? 1 Answer
Efficient Way to Create/Destroy and Switch Between Player GameObjects 1 Answer
Select Car - Multiple prefabs 1 Answer