I have a cupboard with 2 colliders - one for cupboard and one for it's box. When I press on the box, I want to open/close it. It worked fine, but now by some reason it only work when I press on the edge on the box. When click on the center, it don't work.
Video: https://youtu.be/OozsAi7KNzs
Here is the code, which play animation (open/close cupboard), when I press on the box:
public Animation[] animations; public string[] animationName; public bool playOneDirection; // should revert animation speed after second playing? public AudioSource myAudioOpen; public AudioSource myAudioClose; private bool isDoorClosed; private bool isAimationReadyToPlay = true; private Collider thisCollider; public void Start() { thisCollider = GetComponent<Collider>(); } void Update () { if (Input.GetButton("Fire1")) if(DoPlayerLookAtButton() && isAimationReadyToPlay) OpenCloseDoor(); } bool DoPlayerLookAtButton() { RaycastHit _hit; Ray _ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); bool isHit = Physics.Raycast(_ray, out _hit, 1.5f); if (isHit && _hit.collider == thisCollider) return true; else return false; } public void OpenCloseDoor() { if (!isDoorClosed) // Play animation with normal speed { myAudioOpen.Play(); for (int i = 0; i < animations.Length; i++) { animations[i][animationName[i]].speed = 1.0f; animations[i].Play(); } } if(playOneDirection) return; if (isDoorClosed) // Play animation with revert speed { myAudioClose.Play(); for (int i = 0; i < animations.Length; i++) { animations[i][animationName[i]].speed = -1.0f; animations[i][animationName[i]].time = animations[i][animationName[i]].length; animations[i].Play(); } } StartCoroutine("DelayBetweenAnimations"); isDoorClosed = !isDoorClosed; } IEnumerator DelayBetweenAnimations() { isAimationReadyToPlay = false; yield return new WaitForSeconds(0.5f); isAimationReadyToPlay = true; } 