I’m trying to let the character be able to open a door on mousing over it and pressing e.
I have tried a script which rotates and moves the door which successfully opens it but on clicking e a second time the door moves forward from the doorway.
var door : GameObject;
private var x : float;
x = 2.6;
private var y : float;
y = 1.4;
private var rot : int;
rot = 240;
private var mouse : boolean = false;
function OnMouseOver ()
{
mouse = true;
}
function OnMouseExit ()
{
mouse = false;
}
function Update () {
if(Input.GetKeyDown("e") && mouse == true)
{
door.transform.Translate(x,y,0);
door.transform.Rotate(0,0,rot);
rot = -1 * rot;
}
}
I have also tried using two door and open and a closed one and simply translating them. The open door moves into place on clicking e and the closed door moves out of sight but the process is not reversing properly
var y : float;
y = 5;
private var mouse: boolean;
mouse = false;
var initial : GameObject;
var attached : GameObject;
function OnMouseEnter
{
mouse = true;
}
function OnMouseExit
{
mouse = false;
}
function Update
{
if (mouse = true && input.GetKeyDown (“e”))
{
initial.Tranform.translate (0,y,0);
attached.Transform.translate (0,y,0);
y = y * -1;
thanks for the help