- Home /
Desert Fortress Pack asset store
I have an asset from the asset store called desertot fortress pack and have a problem with the door animation. They can open and close but I want to know if you can give them a certain time limit to be open and then close after that time has ended. Any ideas.
(The door script is below)
using UnityEngine; using System.Collections;
//Instruction: //Make an empty game object and call it "Door" //Rename your 3D door model to "Body" //Parent a "Body" object to "Door" //Make sure thet a "Door" object is in left down corner of "Body" object. The place where a Door Hinge need be //Add a box collider to "Door" object and make it much bigger then the "Body" model, mark it trigger //Assign this script to a "Door" game object that have box collider with trigger enabled //Press "e" (Default) to open and close the door //Make sure the main character is tagged "player"
public class open_door : MonoBehaviour { public float smooth = (float)2.0; public float DoorOpenAngle = (float)110.0; public float DoorCloseAngle = (float)0.0; public bool open = false; public bool enter = false; public string defined_key = "e";
// Update is called once per frame
void Update ()
{
if(open == true)
{
var target = Quaternion.Euler (transform.localRotation.x, DoorOpenAngle, transform.localRotation.z);
// Dampen towards the target rotation
transform.localRotation = Quaternion.Slerp(transform.localRotation, target,
Time.deltaTime * smooth);
}
if(open == false)
{
var target1 = Quaternion.Euler (transform.localRotation.x, DoorCloseAngle, transform.localRotation.z);
// Dampen towards the target rotation
transform.localRotation = Quaternion.Slerp(transform.localRotation, target1,
Time.deltaTime * smooth);
}
if(enter == true)
{
if(Input.GetKeyDown(defined_key))
{
open = !open;
}
}
}
//Activate the Main function when player is near the door
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
//Debug.Log("Trigger Enter");
(enter) = true;
}
}
//Deactivate the Main function when player is go away from door
void OnTriggerExit (Collider other)
{
if (other.gameObject.tag == "Player")
{
//Debug.Log("Trigger Exit");
(enter) = false;
}
}
//@youtube.com/user/maksimum654321
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613173605im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Unity error, can't modify transform.position value 1 Answer
When dragging a Door open using RIGIDBODYSCRIPT Plays sound. 1 Answer
Door that changes level on character collision script help? 1 Answer
About door opening with mousemovement! 5 Answers