Noob question for my first project.
I want to make a GameObject ‘bigBrother’ appear when another two objects collide.
I’ve been trying to do this by having it inactive and using SetActive with an if statement, but I can’t make it work and I realised I can’t even do this without the If statement, not even with a script that says nothing else but SetActive on Start or Wake or Update… I thought that perhaps it is because Unity can’t see objects that are inactive at the start of the game, and some forum posts suggest making the inactive prefab a child of an active empty (Enabling a disabled prefab in the scene - Questions & Answers - Unity Discussions) but this doesn’t seem to make a difference.
So I figure SetActive is not the way and I am trying out Instantiate. This works insofar as it creates a clone in the game but one that is inactive and I can’t get it to activate! I have seen examples of code that just say SetActive.‘name of prefab’ that are supposed to activate the just instantiated clone, but maybe I need to refer to the clone specifically? The in-game name is suffixed with ‘(clone)’
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnBigBrother : MonoBehaviour
{
public GameObject bigBrother;
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Wall")
{
Instantiate(bigBrother);
bigBrother.SetActive(true);
}
}
}