- Home /
Activating Objects with collision of another objects
Hi experts, I'm giving my first steps with Unity and doing my first tutorial, Roll a Ball tutorial.
After doing it completely I was trying to add something, I want to set to active every object that I deactivated by picking up the collectables when the ball hits the walls
I added this code to the ball (player) Script trying to do so but does not work:
private GameObject[] pickups = new GameObject[12];
void OnCollisionEnter(Collision col){
if (col.gameObject.CompareTag ("Wall")) {
pickups = GameObject.FindGameObjectsWithTag("Pick Up");
foreach(GameObject go in pickups){
go.SetActive(true);
}
}
Hope that someone can help me with this,
Best Jose
You cannot assign an deactivated game object. You have to assign them, then deactivate.
Answer by LaneFox · Aug 27, 2015 at 05:09 PM
Like @Nirvana33 stated in comment.
Why not just get the collection at the Start, then turn all of them on? It's basically the same thing, except you don't have to make the collection right before you do it since its already there.
Your answer
![](https://koobas.hobune.stream/wayback/20220612001637im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Does Unity Script syntax change from release to release? If so how much? 4 Answers
Disable Box Collider on Tagged Object 2 Answers
My boolean doesen't active no matter what! 2 Answers
Character Controller NOT COLLIDING. 0 Answers
What is floating point precision limitations and how to deal with it? 1 Answer