Search Unity

[SOLVED] My wait function isn't working

Discussion in 'AR/VR (XR) Discussion' started by LadyLegend, Apr 22, 2020.

  1. LadyLegend

    LadyLegend

    Joined:
    Oct 6, 2017
    Posts:
    50
    I did search and copied examples and It just isn't working for me.
    None of the debugs are showing up and I did test a debug in the start function and that worked so its just the coroutine.



    Code (CSharp):
    1. void Start()
    2.     {
    3.         if (ik == null) ik = GetComponent<FullBodyBipedIK>();
    4.         StartCoroutine("waitFiveSeconds");
    5.         lActive = true;
    6.         rActive = true;
    7.  
    8.     }
    9.  
    10.     private void LateUpdate()
    11.     {
    12.  
    13.         if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger) && lActive == false)
    14.         {
    15.             leftGrabber.GetComponent<OVRGrabber>().enabled = true;
    16.             lActive = true;
    17.         }
    18.  
    19.  
    20.         if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger) && rActive == false)
    21.         {
    22.             rightGrabber.GetComponent<OVRGrabber>().enabled = true;
    23.             rActive = true;
    24.         }
    25.  
    26.         float leftHandWeightTarget = lActive || leftGrab.inhand == true ? 1f : 0f;
    27.         ik.solver.leftHandEffector.positionWeight = Mathf.MoveTowards(ik.solver.leftHandEffector.positionWeight, leftHandWeightTarget, Time.deltaTime * weightBlendSpeed);
    28.         ik.solver.leftHandEffector.rotationWeight = ik.solver.leftHandEffector.positionWeight;
    29.  
    30.         float rightHandWeightTarget = rActive || rightGrab.inhand == true ? 1f : 0f;
    31.         ik.solver.rightHandEffector.positionWeight = Mathf.MoveTowards(ik.solver.rightHandEffector.positionWeight, rightHandWeightTarget, Time.deltaTime * weightBlendSpeed);
    32.         ik.solver.rightHandEffector.rotationWeight = ik.solver.rightHandEffector.positionWeight;
    33.  
    34.  
    35.  
    36.  
    37.     }
    38.     IEnumerable waitFiveSeconds()
    39.     {
    40.         Debug.Log("start wait");
    41.         yield return new WaitForSeconds(5);
    42.             Debug.Log("waited");
    43.             if (leftGrab.inhand == false)
    44.             {
    45.  
    46.                 lActive = false;
    47.                 leftGrabber.GetComponent<OVRGrabber>().enabled = false;
    48.             }
    49.             if (rightGrab.inhand == false)
    50.             {
    51.                 rActive = false;
    52.                 rightGrabber.GetComponent<OVRGrabber>().enabled = false;
    53.             }
    54.  
    55.        
    56.      
    57.     }
     
  2. Mystogan98

    Mystogan98

    Joined:
    Apr 26, 2017
    Posts:
    5
    Coroutines return IEnumerator, not IEnumerable.
    You should declare it this way :
    private IEnumerator WaitFiveSeconds()


    You can also call it this way :
    StartCoroutine(WaitFiveSeconds());
    , I find it better, especially because you can send parameters this way.
     
  3. LadyLegend

    LadyLegend

    Joined:
    Oct 6, 2017
    Posts:
    50
    Omg I haven't tried yet but I'm sure it'll work because when I enter code I have a habit of selecting the suggested code smh thank you I'll edit this solved when I test it out