Hello everybody, Im starting with unity, and this is my first thread in this forum. Congrats for the quality of the forum. I am very motivated with this program, and Im watching a lot of tutorials everywhere, but im stuck with something and I dont find anywhere where the mistake is.
Im doing the animation of a door opening and closing, with a raycast. There are a lot of tutorials about it, but all of them are using different syntax in the function to activate an animation, as all of them are programed for older versions, and it has changed for Unity 5. That´s why Im not sure if it is a syntax problem or something with the animation, and, in that case, what could be wrongâŚ
I add the code from the script atached to the first person controller. You can check just what in Bold letters is. everything else is working fine. I also attach the pictures to show how the animation is added to the gameobject, the script to the First person controller, and the animation file.
Sorry for the long text but I wanted to explain as clear as possible. Thanks in advanced. I have been a whole day looking for the mistake and I dont understand whats wrongâŚ
#pragma strict
private var guiShow : boolean = false;
var isOpen : boolean = false;
var door : GameObject;
var rayLength = 10;
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == âDoorâ)
{
guiShow = true;
if(Input.GetKeyDown(âeâ) && isOpen == false)
{
door.GetComponent.().Play(âDoorOpenâ); //Here it doesnt activate the animation
isOpen = true; //isOpen is activated
guiShow = false; //guiShow is deactivated
}
else if(Input.GetKeyDown(âeâ) && isOpen == true)
{
door.GetComponent.().Play(âDoorCloseâ);
isOpen = false;
guiShow = false;
}
}
}
else
{
guiShow = false;
}
print ("IsOpen = â+isOpen+â ; fwd = â+fwd+â ; hit = â+hit+â ; TransPosition = â+transform.position+â ; hit.collider.gameObject.tag = "+hit.collider.gameObject.tag);
}
function OnGUI()
{
if(guiShow == true && isOpen == false)
{
GUI.Box(Rect(Screen.width / 2, Screen.height / 2, 100, 25), âUse Doorâ);
}
}
print ("IsOpen = â+isOpen+â ; fwd = â+fwd+â ; hit = â+hit+â ; TransPosition = â+transform.position+â ; hit.collider.gameObject.tag = "+hit.collider.gameObject.tag);
}
function OnGUI()
{
if(guiShow == true && isOpen == false)
{
GUI.Box(Rect(Screen.width / 2, Screen.height / 2, 100, 25), âUse Doorâ);
}
}