What does it mean?

Updated on August 5, 2014 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
7 on August 4, 2014

Hi
What does it mean?

if (!GameObject.FindGameObjectWithTag(“E”))

It’s if the game object with that tag isn’t find?

  • Liked by
Reply
2 on August 4, 2014

It can be read as : If FindGameObjectWithTag does NOT return a reference to anything.

But I’m actually not sure, can you post where you’re seeing this from?

on August 5, 2014

In Make a Game course, In GameMaster script, we have :

var musicPreFab : Transform;
    
    function Start ()
    {
       if(!GameObject.FindGameObjectWithTag("MM"))
            var mManager = Instantiate (musicPreFab, transform.position, Quaternion.identity);
            mManager.name = musicPreFab.name;
            DontDestroyOnLoad (mManager);
    }

I want to say, when there isn’t any gameobject with “e” tag, do OnGUI ();
What should I do?

on August 5, 2014

to do something on gui just simply use that function on gui, or make a boolean trigger, so if the gameobject isnt in the scene, activate a bool, and in the OnGUI function check that bool and do something, you got it?

EDIT—— EXAMPLE:

var trigger : boolean;
 function Start ()
 {
          if(!GameObject.FindGameObjectWithTag("MM"))
         {
           trigger = true;
          }
           else{trigger = false;}
 }
function OnGUI(){
       if(trigger){
            // SOME GUI STUFF TO DO HERE
           }
}
Show more replies
  • Liked by
Reply
Cancel
0 on August 5, 2014

that is like: if the script CANT find that gameobject DO something, only if you CANT find it… i guess D:
i never did that anyway xD

  • Liked by
Reply
Cancel
1 on August 5, 2014
void OnGui()
{
   if (GameObject.FindGameObjectWithTag(“E”)) return; // do this on the first line
...
on August 5, 2014

yep 

function OnGUI(){
if(!GameObject.FindGameObjectWithTag("e"))
   {
     //gui stuff
   }
}

Show more replies
  • Liked by
Reply
Cancel
0 on August 5, 2014

Yes, thanks, so helpful

  • Liked by
Reply
Cancel