First off, I SINCERELY apologize if this is not the correct place to ask this question, however I really need help with this script and my question keeps getting deleted before being up for 30 seconds.
I have this script assigned to a door that allows the player to open the door when the player approaches the door and clicks on the left mouse button. However, the script tells the door to rotate open, like a traditional door, but I want the door to slide open instead.
How would I edit the script so that the door slides open rather than rotates open?
I’m guessing the solution is something along the lines of changing transform.rotation to transform.position, but I’m not quite sure, I have only been learning C# since yesterday afternoon.
I do know that the position of the door when open would be at 0.001 in the x coordinate.
using UnityEngine;
using System.Collections;
public class DoorScript : MonoBehaviour {
public bool open = false;
public float doorOpenAngle = 90f;
public float doorCloseAngle = 0f;
public float smooth = 2f;
void Start ()
{
}
public void ChangeDoorState()
{
open = !open;
}
void Update ()
{
if(open) //open == true
{
Quaternion targetRotation = Quaternion.Euler(0, doorOpenAngle, 0);
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, smooth * Time.deltaTime);
}
else
{
Quaternion targetRotation2 = Quaternion.Euler(0, doorCloseAngle, 0);
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation2, smooth * Time.deltaTime);
}
}
}