Open/Close window with Mouse click

Hi Guys, I’m the latest P.I.T.A. NOOB with the standard “I can’t do this…” problem! First off, I know virtually nothing about writing script in any language, but after reading a variety of posts I know I’m gonna need to.
My problem is simple, I’m building a walkthrough of a building that has windows and doors that I would like to open and close with a mouse click and also play the appropriate sounds. I have found the right scripts for doing this with the doors, but no matter what I do to alter the scripts to suit the windows, nothing works. No I take that back, I can get them to move sideways or back and forth. Just not slide up and down! Any hints would be appreciated! :sweat_smile:

I’d position 2 empties, one for open and one for closed, for each window to use as transform values, and move the window between them.

var windowOpenPosition : Transform;
var windowClosedPosition : Transform;
var isClosed : boolean = true;

function OnMouseDown () {
if (isClosed) {
OpenWindow();
}
else {
CloseWindow();	
}
}

function OpenWindow () {   
   transform.Translate(windowOpenPosition.position - transform.position);
   isClosed = false;
	}  	
function CloseWindow () {  
   transform.Translate(windowClosedPosition.position - transform.position);
	isClosed = true;
}

Attach this script to the window object, drag the positional empties into the appropriate slots in the inspector, and you’re ready to go. This is an easy way to get accurate positioning, no need to mess with vectors or push stuff around.

HTH - and welcome to the forums!

Many thanks for that, almost exactly what I need, and thanks for the warm welcome. I know most of the questions asked here by those of us less informed can be tedious at times, but I for one really do appreciate any help given.

I think I can figure out how to add the appropriate sound effects. I already have a script that does that for doors so I should be able to extract the sections I need.

Is there a way to slow down the movement between open and closed, using the script you gave me? :?: It really isn’t important to my project, just wondering, is all!