Keydoor problem
Hello. I have got problem with my script. When I already take the key and try to open the door it makes sound but it doesnt open, it doesnt change y-positioning. Any help ? Code : {
public static bool doorKey;
public bool open;
public bool close;
public bool inTrigger;
public Transform doorHinge;
public AudioSource audioSource;
public Canvas canopen;
public Canvas keycanvas;
private readonly Quaternion openRot = Quaternion.Euler(0.0f, 90.0f, 0.0f);
private readonly Quaternion closeRot = Quaternion.Euler(0.0f, 0.0f, 0.0f);
private void Start()
{
this.open = this.doorHinge.rotation.y >= 90.0f;
this.close = this.doorHinge.rotation.y >= 0.0f;
}
private void OnTriggerEnter(Collider other)
{
this.inTrigger = true;
}
private void OnTriggerExit(Collider other)
{
this.inTrigger = false;
keycanvas.gameObject.SetActive (false);
canopen.gameObject.SetActive (false);
}
private bool SetMeOnly()
{
this.open = this.close = false;
return true;
}
private void Update()
{
if (this.inTrigger)
if (this.close && Input.GetKeyDown(KeyCode.E))
if (doorKey)
{
this.open = this.SetMeOnly();
this.audioSource.Play();
}
else if (this.open && Input.GetKeyDown(KeyCode.E))
{
this.close = this.SetMeOnly();
this.audioSource.Play();
}
}
void OnGUI()
{
if (inTrigger)
{
if (open)
{
canopen.gameObject.SetActive (true);
}
else
{
if (doorKey)
{
canopen.gameObject.SetActive (true);
}
else
{
keycanvas.gameObject.SetActive (true);
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Why Quaternion.Euler can't rotate 360 Degrees 0 Answers
Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation. 1 Answer
Quaternion/World Local rotation problem 0 Answers
How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 1 Answer
Space Shooter Tutorial tilting extra 0 Answers