|
|
|
| View previous topic :: View next topic |
weetie
Joined: 12 Aug 2009 Posts: 14
|
Posted: Mon Nov 02, 2009 3:58 pm Post subject: Object Visibility Toggle |
|
|
|
| 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 |
|
|
dreamora
Joined: 05 Apr 2008 Posts: 6659 Location: Zürich, Switzerland
|
|
| Back to top |
|
|
weetie
Joined: 12 Aug 2009 Posts: 14
|
Posted: Mon Nov 02, 2009 4:44 pm Post subject: |
|
|
|
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 |
|
|
andeeee Forum Moderator

Joined: 19 Jul 2005 Posts: 1603 Location: Blackpool, United Kingdom
|
Posted: Tue Nov 03, 2009 8:51 pm Post subject: |
|
|
|
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 |
|
|
|
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
|
|
|
|
|
|