UNITY - Make a gameobject inactive and active





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have game objects which is button (Called as tiles), when the button is clicked it will be inactive and there's a condition to be tested if the condition is true the button will be destroyed but if its false the button will back to its active status.



My game Manager script (The condition):



public void checkword()
{
wordBuilded = displayer.text.ToString();

if (txtContents.Contains(wordBuilded))
{
Debug.Log(wordBuilded + " Is on the list");
wordScore++;
Debug.Log(wordScore);
}
else
{
Debug.Log("Someting is wrong..");
FindObjectOfType<LetterTiles>().tileStatus();
}

}


On my Button (Tile) script (Script attached to the buttons):



public void letterClick()
{
gameManager.currentWord += letter;
gameObject.SetActive(false);

}

public void tileStatus()
{
gameObject.SetActive(true);
}









share|improve this question























  • you didn't mention what the problem is

    – Jimmar
    Nov 27 '18 at 0:32











  • I want the button object to re appear when the condition is false

    – Munggo Lloyd
    Nov 27 '18 at 0:55


















0















I have game objects which is button (Called as tiles), when the button is clicked it will be inactive and there's a condition to be tested if the condition is true the button will be destroyed but if its false the button will back to its active status.



My game Manager script (The condition):



public void checkword()
{
wordBuilded = displayer.text.ToString();

if (txtContents.Contains(wordBuilded))
{
Debug.Log(wordBuilded + " Is on the list");
wordScore++;
Debug.Log(wordScore);
}
else
{
Debug.Log("Someting is wrong..");
FindObjectOfType<LetterTiles>().tileStatus();
}

}


On my Button (Tile) script (Script attached to the buttons):



public void letterClick()
{
gameManager.currentWord += letter;
gameObject.SetActive(false);

}

public void tileStatus()
{
gameObject.SetActive(true);
}









share|improve this question























  • you didn't mention what the problem is

    – Jimmar
    Nov 27 '18 at 0:32











  • I want the button object to re appear when the condition is false

    – Munggo Lloyd
    Nov 27 '18 at 0:55














0












0








0








I have game objects which is button (Called as tiles), when the button is clicked it will be inactive and there's a condition to be tested if the condition is true the button will be destroyed but if its false the button will back to its active status.



My game Manager script (The condition):



public void checkword()
{
wordBuilded = displayer.text.ToString();

if (txtContents.Contains(wordBuilded))
{
Debug.Log(wordBuilded + " Is on the list");
wordScore++;
Debug.Log(wordScore);
}
else
{
Debug.Log("Someting is wrong..");
FindObjectOfType<LetterTiles>().tileStatus();
}

}


On my Button (Tile) script (Script attached to the buttons):



public void letterClick()
{
gameManager.currentWord += letter;
gameObject.SetActive(false);

}

public void tileStatus()
{
gameObject.SetActive(true);
}









share|improve this question














I have game objects which is button (Called as tiles), when the button is clicked it will be inactive and there's a condition to be tested if the condition is true the button will be destroyed but if its false the button will back to its active status.



My game Manager script (The condition):



public void checkword()
{
wordBuilded = displayer.text.ToString();

if (txtContents.Contains(wordBuilded))
{
Debug.Log(wordBuilded + " Is on the list");
wordScore++;
Debug.Log(wordScore);
}
else
{
Debug.Log("Someting is wrong..");
FindObjectOfType<LetterTiles>().tileStatus();
}

}


On my Button (Tile) script (Script attached to the buttons):



public void letterClick()
{
gameManager.currentWord += letter;
gameObject.SetActive(false);

}

public void tileStatus()
{
gameObject.SetActive(true);
}






c# visual-studio unity3d button






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 23:59









Munggo LloydMunggo Lloyd

83




83













  • you didn't mention what the problem is

    – Jimmar
    Nov 27 '18 at 0:32











  • I want the button object to re appear when the condition is false

    – Munggo Lloyd
    Nov 27 '18 at 0:55



















  • you didn't mention what the problem is

    – Jimmar
    Nov 27 '18 at 0:32











  • I want the button object to re appear when the condition is false

    – Munggo Lloyd
    Nov 27 '18 at 0:55

















you didn't mention what the problem is

– Jimmar
Nov 27 '18 at 0:32





you didn't mention what the problem is

– Jimmar
Nov 27 '18 at 0:32













I want the button object to re appear when the condition is false

– Munggo Lloyd
Nov 27 '18 at 0:55





I want the button object to re appear when the condition is false

– Munggo Lloyd
Nov 27 '18 at 0:55












1 Answer
1






active

oldest

votes


















0














When an object is deactivated Unity won't find it using FindObjectOfType.



either keep a local reference to the object [the button] in the game manager before you disable it or hide the button in a different way.



Since you are using a Button, you can use the interactable property of the button to make it disabled [and if you want it to be hidden then change the disabled color to transparent] like:



gameobject.GetComponent<Button>().interactable = false;






share|improve this answer
























  • Thanks for your answers but how will I put a local reference of the object if I'm using an array for that object?

    – Munggo Lloyd
    Nov 27 '18 at 1:28






  • 1





    loop through the array and compare with name and place it locally , ofc it can be saved many other ways also .

    – LumbusterTick
    Nov 27 '18 at 8:06











  • @MunggoLloyd if you have the objects ready when the game starts, you can find all objects of the type LetterTiles and save them in a list. I'd use the interactable trick instead of the deactivating the buttons though. If you still need to deactivate the game object comment again and I'll edit my answer to include a how to sample to do it.

    – Jimmar
    Nov 27 '18 at 23:45













  • Hi @Jimmar I fixed it already with using Interactable and changing the color as you said thank you very much for helping me. But I have a new problem maybe you can help me out? stackoverflow.com/questions/53516024/…

    – Munggo Lloyd
    Nov 28 '18 at 9:27












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490875%2funity-make-a-gameobject-inactive-and-active%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














When an object is deactivated Unity won't find it using FindObjectOfType.



either keep a local reference to the object [the button] in the game manager before you disable it or hide the button in a different way.



Since you are using a Button, you can use the interactable property of the button to make it disabled [and if you want it to be hidden then change the disabled color to transparent] like:



gameobject.GetComponent<Button>().interactable = false;






share|improve this answer
























  • Thanks for your answers but how will I put a local reference of the object if I'm using an array for that object?

    – Munggo Lloyd
    Nov 27 '18 at 1:28






  • 1





    loop through the array and compare with name and place it locally , ofc it can be saved many other ways also .

    – LumbusterTick
    Nov 27 '18 at 8:06











  • @MunggoLloyd if you have the objects ready when the game starts, you can find all objects of the type LetterTiles and save them in a list. I'd use the interactable trick instead of the deactivating the buttons though. If you still need to deactivate the game object comment again and I'll edit my answer to include a how to sample to do it.

    – Jimmar
    Nov 27 '18 at 23:45













  • Hi @Jimmar I fixed it already with using Interactable and changing the color as you said thank you very much for helping me. But I have a new problem maybe you can help me out? stackoverflow.com/questions/53516024/…

    – Munggo Lloyd
    Nov 28 '18 at 9:27
















0














When an object is deactivated Unity won't find it using FindObjectOfType.



either keep a local reference to the object [the button] in the game manager before you disable it or hide the button in a different way.



Since you are using a Button, you can use the interactable property of the button to make it disabled [and if you want it to be hidden then change the disabled color to transparent] like:



gameobject.GetComponent<Button>().interactable = false;






share|improve this answer
























  • Thanks for your answers but how will I put a local reference of the object if I'm using an array for that object?

    – Munggo Lloyd
    Nov 27 '18 at 1:28






  • 1





    loop through the array and compare with name and place it locally , ofc it can be saved many other ways also .

    – LumbusterTick
    Nov 27 '18 at 8:06











  • @MunggoLloyd if you have the objects ready when the game starts, you can find all objects of the type LetterTiles and save them in a list. I'd use the interactable trick instead of the deactivating the buttons though. If you still need to deactivate the game object comment again and I'll edit my answer to include a how to sample to do it.

    – Jimmar
    Nov 27 '18 at 23:45













  • Hi @Jimmar I fixed it already with using Interactable and changing the color as you said thank you very much for helping me. But I have a new problem maybe you can help me out? stackoverflow.com/questions/53516024/…

    – Munggo Lloyd
    Nov 28 '18 at 9:27














0












0








0







When an object is deactivated Unity won't find it using FindObjectOfType.



either keep a local reference to the object [the button] in the game manager before you disable it or hide the button in a different way.



Since you are using a Button, you can use the interactable property of the button to make it disabled [and if you want it to be hidden then change the disabled color to transparent] like:



gameobject.GetComponent<Button>().interactable = false;






share|improve this answer













When an object is deactivated Unity won't find it using FindObjectOfType.



either keep a local reference to the object [the button] in the game manager before you disable it or hide the button in a different way.



Since you are using a Button, you can use the interactable property of the button to make it disabled [and if you want it to be hidden then change the disabled color to transparent] like:



gameobject.GetComponent<Button>().interactable = false;







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 1:04









JimmarJimmar

1,63711530




1,63711530













  • Thanks for your answers but how will I put a local reference of the object if I'm using an array for that object?

    – Munggo Lloyd
    Nov 27 '18 at 1:28






  • 1





    loop through the array and compare with name and place it locally , ofc it can be saved many other ways also .

    – LumbusterTick
    Nov 27 '18 at 8:06











  • @MunggoLloyd if you have the objects ready when the game starts, you can find all objects of the type LetterTiles and save them in a list. I'd use the interactable trick instead of the deactivating the buttons though. If you still need to deactivate the game object comment again and I'll edit my answer to include a how to sample to do it.

    – Jimmar
    Nov 27 '18 at 23:45













  • Hi @Jimmar I fixed it already with using Interactable and changing the color as you said thank you very much for helping me. But I have a new problem maybe you can help me out? stackoverflow.com/questions/53516024/…

    – Munggo Lloyd
    Nov 28 '18 at 9:27



















  • Thanks for your answers but how will I put a local reference of the object if I'm using an array for that object?

    – Munggo Lloyd
    Nov 27 '18 at 1:28






  • 1





    loop through the array and compare with name and place it locally , ofc it can be saved many other ways also .

    – LumbusterTick
    Nov 27 '18 at 8:06











  • @MunggoLloyd if you have the objects ready when the game starts, you can find all objects of the type LetterTiles and save them in a list. I'd use the interactable trick instead of the deactivating the buttons though. If you still need to deactivate the game object comment again and I'll edit my answer to include a how to sample to do it.

    – Jimmar
    Nov 27 '18 at 23:45













  • Hi @Jimmar I fixed it already with using Interactable and changing the color as you said thank you very much for helping me. But I have a new problem maybe you can help me out? stackoverflow.com/questions/53516024/…

    – Munggo Lloyd
    Nov 28 '18 at 9:27

















Thanks for your answers but how will I put a local reference of the object if I'm using an array for that object?

– Munggo Lloyd
Nov 27 '18 at 1:28





Thanks for your answers but how will I put a local reference of the object if I'm using an array for that object?

– Munggo Lloyd
Nov 27 '18 at 1:28




1




1





loop through the array and compare with name and place it locally , ofc it can be saved many other ways also .

– LumbusterTick
Nov 27 '18 at 8:06





loop through the array and compare with name and place it locally , ofc it can be saved many other ways also .

– LumbusterTick
Nov 27 '18 at 8:06













@MunggoLloyd if you have the objects ready when the game starts, you can find all objects of the type LetterTiles and save them in a list. I'd use the interactable trick instead of the deactivating the buttons though. If you still need to deactivate the game object comment again and I'll edit my answer to include a how to sample to do it.

– Jimmar
Nov 27 '18 at 23:45







@MunggoLloyd if you have the objects ready when the game starts, you can find all objects of the type LetterTiles and save them in a list. I'd use the interactable trick instead of the deactivating the buttons though. If you still need to deactivate the game object comment again and I'll edit my answer to include a how to sample to do it.

– Jimmar
Nov 27 '18 at 23:45















Hi @Jimmar I fixed it already with using Interactable and changing the color as you said thank you very much for helping me. But I have a new problem maybe you can help me out? stackoverflow.com/questions/53516024/…

– Munggo Lloyd
Nov 28 '18 at 9:27





Hi @Jimmar I fixed it already with using Interactable and changing the color as you said thank you very much for helping me. But I have a new problem maybe you can help me out? stackoverflow.com/questions/53516024/…

– Munggo Lloyd
Nov 28 '18 at 9:27




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490875%2funity-make-a-gameobject-inactive-and-active%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen