The question is answered, right answer was accepted
How to check if object is active?
if (game_object.active == true)
I'm looking for another way to do it because this way gives me a warning message: "warning CS0618: `UnityEngine.GameObject.active' is obsolete"
Answer by vexe · Sep 14, 2014 at 04:57 PM
Use activeSelf
print(go.activeSelf ? "Active" : "Inactive");
Also worth checking: SetActive, activeInHierarchy
wha???????...... o_O I just answered you... hello?
if (myGameObject.activeSelf)
print ("Active")
maybe he asked again because like no beginner understands what you answered...
$$anonymous$$aybe the ternary operator confused you?
int x = condition ? 10 : 15;
is the equivalent of:
int x;
if (condition)
x = 10;
else x = 15;
'if' takes a boolean expression which could either return a true or false. bool variables could hold a value of true or false so you could pass them to the if statement so you don't need to say:
if (condition == true)
doStuff();
you could just say:
if (condition)
doStuff();
Thank you, vexe, your explanation is very detailed <3
$$anonymous$$aybe you need to consider a program$$anonymous$$g course before you approach Unity and game development in general. This is one of the many things I don't like about Unity, is that they make it sound like you don't need any program$$anonymous$$g skills to get started 'making games' - we end up with basic 101 program$$anonymous$$g questions on a technical Unity Q/A site, then you get moderators and such telling the questerioners that UA is for asking technical questions about Unity3D! forgetting the fact that Unity IS ACTUALLY promoting this stuff... (ranting about Unity, not you dear Samuel - there's nothing wrong about being a beginner - we all were)
Dear Samuel, before you build something very sophisticated as games, you need to know your tools - you need to know your language very well :) - Jamie $$anonymous$$ing is a good place to start. Start with his basic C# series and move up. Best of luck.
Also don't relate "not knowing" into giving up and asking - you could have easily found the answer by just looking at the doc for GameObject.
there is no need to be this rude its not known formula that you used to answer and you assumed that every programmer will understand it " i have been studying program$$anonymous$$g for three years now and i didnt understand your code at first " also i dont think you should assume every one asking here is program$$anonymous$$g expert most of people learn unity have no program$$anonymous$$g background and they started learning program$$anonymous$$g as they learn unity so i think you should assume when you answer someone question that he is beginner
also after all it wasn't big deal to just write simple answer that every one could understand like the answer in the comment below its almost the same amount of code with less amount of explanation needed after it "no need to show skills"
Dude, smartass, you should refer to the title of this website... A UNITY FORU$$anonymous$$ for program$$anonymous$$g solutions... not a Unity feedback/opinion website. And you DON'T NEED TO RUB in his face that he is a beginner: "(ranting about Unity, not you dear Samuel - there's nothing wrong about being a beginner - we all were)". Nobody cares about your opinion, so you can just keep your bullshit to yourself. Your part was done when you explained what the ternary operator does. I actually started program$$anonymous$$g through watching others do unity C# and EXPERI$$anonymous$$ENTING on my own by also asking questions, and then moved to other program$$anonymous$$g languages later on, but this helped me pick up fundamentals. Not everyone is the type of person who watches some random person code, and become a professional.
Google indexes the answers on this forum, so when people are just trying to get a simple answer for syntax they don't need this kind of petty, gatekeepery garbage wasting their time. Don't want to answer a noob question? Don't answer it. Problem solved, move on, don't be a dick. Can't not be a dick? Then please know that you are, sir, a dick, and you have wasted not only your own time, but the time of everyone who just wanted a simple syntax answer and had the absolute gall to use a search engine on the internet to find it.
I am so confused, one person asks a question then another one aswers it in a way they assume is the most comprehensible and neat and when it's not understood he even goes into more detail and recommends a way how to improve oneself but then there are other people who just assume that he has some kind of prejudice. What if the way he recommends is the way that worked for him? Is it so hard to google one more step? I mean if he really wants to learn I would assume he is prepared to go down the rabbit hole if he didn't master the basics first. When did Unity forum become a third-rate drama forum... no idea, please guys be less touchy-feely.
Answer by jfn73150 · Sep 21, 2018 at 05:11 PM
I don't know why but it seems some people can't give a simple answer they have to act smart or something... Want to make you feel like you aren't ready... I also know this post is 4 years old.. But seriously... Simple answer is
if(gameObject.ActiveSelf == true)
Sorry it took so long... Answers.Unity can be super helpful.. And sometimes it makes things worse.
@jfn73150 thanks man! This helped me a lot! That kind of answers i like!! But just one tiny detail: it worked for me only with a small "a" in Active if(gameObject.activeSelf == true)
Thank you, I wasn't expecting a Google search to drop me into somebody's hissy fit over being asked a simple question that he had no obligation to answer, and I appreciate you taking the time to do so.
Comepletely agree, thanks so much for a simple solution
Follow this Question
Related Questions
Error CS8025: Parsing Error 3 Answers
How to disable/enable UI panel? 1 Answer
Problem using Raise or Lower terrain & Terrain Tools 0 Answers