Okay, I am trying to have a raycast open a door and then when it is done opening I want the ability to also close the door. I am new to coding with Javascript and Unity so if you have a better way of completing this task and advice is greatly appreciated!. My problem here though is that once I open the door I cannot rewind the animation to close it!. Thanks in advance
~Brady
function Update()
{
var hit : RaycastHit;
var i = 1;
// Check if player is trying to do something
if(Input.GetButton ("Action")) {
//check if we're colliding
if(Physics.Raycast(transform.position, transform.forward, hit, 7)) {
//...with a door
if(hit.collider.gameObject.tag == "door") {
//open door
if(i == 1) {
hit.collider.gameObject.animation.Play("door_open");
i = 2;
}
if(i == 2) {
hit.collider.gameObject.animation.Rewind("door_open");
i = 1;
}
}
}
}
}
This is super old, dormant and refers mostly to the older system. Perhaps its time to write a fresh question.
– meat5000