Object Visibility Toggle

 
Post new topic   Reply to topic    Unity Community Index // UnityGUI
View previous topic :: View next topic  
Author Message
weetie



Joined: 12 Aug 2009
Posts: 14

PostPosted: Mon Nov 02, 2009 3:58 pm    Post subject: Object Visibility Toggle Reply with quote
Code:

function Update () {
if (Input.GetKey ("1")) {
   Mesh144.renderer.enabled = false;
   }
   
}


I've got a few problems here.
First, when I run this I get an error that says Assets/NewBehaviourScript.js(3,9): BCE0005: Unknown identifier:'Mesh144". So I apparently need some other way to identify the object I want to make invisible.
Second, what do I attach this behavior to? the first person controller? the object itself?
Third, what do I need to add to my script so I can toggle visibility on/off using the same key, not just only turn the visibility off?

Thanks for any help
Back to top
View user's profile Send private message
dreamora



Joined: 05 Apr 2008
Posts: 6659
Location: Zürich, Switzerland

PostPosted: Mon Nov 02, 2009 4:06 pm    Post subject: Reply with quote
you need to search for the object or put this on the object you want to affect and use gameObject instead of Mesh144
_________________
Technologies: Unity Pro, iPhone Advanced
Site: GayaSoft & PatchLaunch Technology
My Blogs:My Development & Persistent Online Worlds
Back to top
View user's profile Send private message
weetie



Joined: 12 Aug 2009
Posts: 14

PostPosted: Mon Nov 02, 2009 4:44 pm    Post subject: Reply with quote
thanks Dreamora.

Any idea how I could get this to toggle? I've set it up so (1) turns it off & (2) turns it on, & that'll get me through, but toggling with the same button would be more elegant...
Back to top
View user's profile Send private message
andeeee
Forum Moderator


Joined: 19 Jul 2005
Posts: 1603
Location: Blackpool, United Kingdom

PostPosted: Tue Nov 03, 2009 8:51 pm    Post subject: Reply with quote
You can create a toggle using a boolean variable:-
Code:
var keyIsDown: boolean;

if (Input.GetKey("1") {
   if (!keyIsDown) {
      keyIsDown = true;
      obj.renderer.enabled = !obj.renderer.enabled;
   }
} else {
   keyIsDown = false;
}

_________________
None of you understand... I'm not logged-in here with you - YOU'RE LOGGED-IN HERE WITH ME!
Back to top
View user's profile Send private message
Post new topic   Reply to topic    Unity Community Index // UnityGUI All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum