Question by
Vanity_Myxe · Aug 29, 2016 at 10:26 AM ·
c#animationerrorcoordinates
Door control coordinates being a jerk
So, I was making a FNAF game with help from YT tutorials. I got a script down, but it is spawning the door animation in the wrong coordinates. Here's the code that I use.
using UnityEngine;
using System.Collections;
public class Door: MonoBehaviour
{
public float doorHeight = 2.12f;
public float doorSpeed = 1.0f;
protected bool doorInUse = false;
protected bool doorOpen = false;
IEnumerator openDoor()
{
for (float amount = 0.0f; amount < doorHeight; amount += doorSpeed * Time.deltaTime)
{
Debug.Log("Opening Door: " + amount.ToString());
transform.position = new Vector3(transform.position.x, amount, transform.position.z);
yield return null;
}
doorInUse = false;
doorOpen = true;
}
IEnumerator closeDoor()
{
for (float amount = doorHeight; amount > 0.0f; amount -= doorSpeed * Time.deltaTime)
{
Debug.Log("Closing Door" + amount.ToString());
transform.position = new Vector3(transform.position.x, amount, transform.position.z);
yield return null;
}
doorInUse = false;
doorOpen = false;
}
public void activateDoor()
{
{
if (!doorInUse)
{
doorInUse = true;
if (doorOpen)
StartCoroutine("closeDoor");
else
StartCoroutine("openDoor");
}
}
}
};
When I press a button, it starts closing (the first problem) and is spawning in negative coordinates, though the code uses positive coordinates. Help pls?
Comment
Your answer
Follow this Question
Related Questions
The name animator does not exist in the current context... Help? 1 Answer
.IsPlaying does not exist? 1 Answer
How to fix "no overload for method get component takes 1 arguments" 1 Answer
Trying to get animation to work. Problem with JS. 1 Answer
Setup an animation script, but now mouselook is not working? 0 Answers