Hey there folks,
I’ve created this simple code that is an activated animation to open/close a sliding door when it’s been clicked (well, when the right click is being held down to close it, it also has a seperate script that is almost identical to hold down left click to open it).
I want to be able to limit the distance the door can close, naturally; how can I expand on this code to make it do so?
C#
using UnityEngine;
using System.Collections;
public class cabdoorclose : MonoBehaviour
{
public void OnDoorclose()
{
transform.Translate(Vector3.forward * Time.deltaTime);
}
}
This is the clickable object to open/close the door:
C#
using UnityEngine;
using System.Collections;
public class cabdoorclick : MonoBehaviour
{
public cabdooropen dooropen;
public cabdoorclose doorclose;
void OnMouseEnter ()
{
guiText.text = "Hello World!";
}
void OnMouseOver ()
{
if (Input.GetMouseButton (1)) {
doorclose.OnDoorclose();
}
if (Input.GetMouseButton (0)) {
dooropen.OnDooropen();
}
}
}