BASIC TELEPORTING QUEST: ‘Deactivate Object’ - Solutions

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

1 Like

For this challenge, I guess the solution that was expected was to disable the whole teleporter, you basically set the whole GameObject to SetActive(false) (basically disabling it).

I didn’t want to disable the whole Teleporter as it would basically disappear. I tried to SetActive(false) the BoxCollider component instead and discovered that SetActive was only available for GameObjects.

So I did a quick search in the documentation and here is what I came up with :

 void OnTriggerEnter(Collider other) 
    {
        TeleportPlayer();
        DeactivateObject();
        // Challenge 4: IlluminateArea();
        // Challenge 5: StartCoroutine ("BlinkWorldLight");
        // Challenge 6: TeleportPlayerRandom();
    }

void DeactivateObject()
    {
        BoxCollider boxCollider = GetComponent<BoxCollider>();
        boxCollider.enabled = !boxCollider.enabled;
    }
3 Likes

I like this solution. I ended up disabling the whole teleporter with SetActive(false) and you’re right, I didn’t like how it suddenly disappeared! :laughing:

My solution was to create a new field isActive, which is true by default.

[SerializeField] bool isActive = true;

void OnTriggerEnter(Collider other)
{
    if (!isActive) return;

    TeleportPlayer();
    DeactivateObject();
}

void DeactivateObject()
{
    isActive = false;
}

I tried doing enabled = false, but apparently that only prevents the component’s Update method from running; other methods contine to work, including OnTriggerEnter.

3 Likes

That’s the code that I used for this challenge

 void DeactivateObject()
    {
        BoxCollider boxCollider = GetComponent<BoxCollider>();
        boxCollider.enabled = false;
    }
1 Like

I liked removing the object. Here’s the code I used.

void DeactivateObject()
    {
        BoxCollider boxCollider = GetComponent<BoxCollider>();
        boxCollider.gameObject.SetActive(false);
    }