- Home /
Need Door Radius
I have a door script that allows me to open and close the door the 1 problem I have is that I can open the door from anywhere in the world I want to make it so if I'm near the door it can open
Here's the code.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class doorControl : MonoBehaviour { public float speed; public float angle; public Vector3 direction; // Start is called before the first frame update void Start() { angle = transform.eulerAngles.y; }
// Update is called once per frame
void Update()
{
if(Mathf.Round(transform.eulerAngles.y) != angle)
{
//rotate door
transform.Rotate(direction * speed);
}
if(Input.GetKeyDown(KeyCode.Q))
{
angle = 90f;
direction = Vector3.up;
}
if (Input.GetKeyDown(KeyCode.C))
{
angle = 0f;
direction = -Vector3.up;
}
}
} ,I have a door system that open and closes the door on its axis but I can open it from anywhere in the world I just want it so I can only open the door if I'm near it
Here's the code.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class doorControl : MonoBehaviour { public float speed; public float angle; public Vector3 direction; // Start is called before the first frame update void Start() { angle = transform.eulerAngles.y; }
// Update is called once per frame
void Update()
{
if(Mathf.Round(transform.eulerAngles.y) != angle)
{
//rotate door
transform.Rotate(direction * speed);
}
if(Input.GetKeyDown(KeyCode.Q))
{
angle = 90f;
direction = Vector3.up;
}
if (Input.GetKeyDown(KeyCode.C))
{
angle = 0f;
direction = -Vector3.up;
}
}
}
just check how far away it is using Vector3.Distance();
Your answer
Follow this Question
Related Questions
Multi Switch Door 4 Answers
Scene Change OnCollision Not Working 2 Answers
Opening door with the same key? 1 Answer
Access navmeshagent calculation data? 0 Answers
Door Width Gets Smaller When Rotated 0 Answers