I’m using two scripts. I created a cube and made it a door pivot with a door script created two animations one open door and the other close door. My problem is that the pivot turns but the door doesn’t turn with it.
Both scripts for people to use through a tutorial.
Door.CS
using UnityEngine;
using System.Collections;
public class Door : MonoBehaviour {
private int m_LastIndex;
public void PlayDoorAnim ()
{
if(!GetComponent<Animation>().isPlaying)
{
if(m_LastIndex == 0)
{
GetComponent<Animation>().Play("DoorOpen");
m_LastIndex = 1;
}
else
{
GetComponent<Animation>().Play("DoorClose");
m_LastIndex = 0;
}
}
}
}
InputHandler.CS
using UnityEngine;
using System.Collections;
public class InputHandler : MonoBehaviour
{
void Update ()
{
if (Input.GetMouseButton (0))
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit rayCastHit;
if (Physics.Raycast (ray.origin, ray.direction, out rayCastHit, Mathf.Infinity))
{
Debug.Log ("Mouse Click!");
Door door = rayCastHit.transform.GetComponent<Door>();
if(door)
{
door.PlayDoorAnim();
}
}
}
}
}
Credit to this tutorial