You could translate the position so if you don’t want it to jump to the position. This way might be a little complicated but it works without too many conditionals.
var speed = 6;
var i : float = 0.0;
var canClickDoor = true;
var startPos : Vector3;
function OnMouseDown () {
if(canClickDoor) {
SlideDoor();
canClickDoor = false;
startPos = transform.position;
}
}
function SlideDoor () {
while(i<= 1) {
transform.position = Vector3.Lerp(startPos, Vector3(-18.3864, 0, 0), i);
i += Time.deltaTime * speed;
yield;
}
}
edit: And this is a little off topic, but I just like how it looks. Other ways you could find a way to use would be transform.Translate, or if you add a character controller (which would be strange for a door so I wouldn’t recommend it) you could use GetComponent(CharacterController).Move(). There are a maybe a few other ways you could approach it also, but I won’t get into it so as not to overwhelm you in your first post.