Unable to have door Slide up after pressing Ctrl to move down, Unable to find issue in my code.
I am working on getting a door to slide down in 3D application, I am able to get it to go down, but when I press the button again it doesn't go up, see what I have below:
public class DoorOpenDevice : MonoBehaviour {
[SerializeField] private Vector3 dPos;
private bool _open;
private void Operate()
{
if (_open)
{
Vector3 pos = transform.position - dPos;
transform.position = pos;
}
else
{
Vector3 pos = transform.position + dPos;
transform.position = pos;
}
_open = !_open;
}
}
I have the dPos set to 0, -3, 0 in the Inspector for the door, and then I have a script that is attached to the user that calls Operator, this defines when I can press "Ctrl" on my keyboard and then it drops door down, but when I press again it doesn't go up. public class DeviceOperator : MonoBehaviour { public float radius = 8.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
{
Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius);
foreach(Collider hitCollider in hitColliders)
{
hitCollider.SendMessage("Operate", SendMessageOptions.DontRequireReceiver);
}
}
}
}
Any ideas or nudges in right direction will be appreciated.
Thanks.
$$anonymous$$aybe the radius is not enough to detect the door while it is down?A simple debug.log with the items of the list should reveal that. Tested the code and it works.
Thank you for the reply, that didn't seem to change anything, I added a Debug.Log and found that it works going down, but it never goes back for the second click and no action is taken, Going to try again maybe I missed something in linking the Scripts in the UI.
Your answer
![](https://koobas.hobune.stream/wayback/20220612103700im_/https://answers.unity.com/themes/thub/images/avi.jpg)