I am new to C# and am trying to create a method to cast and check a raycasthit, using a while(). Is this possible? I would prefer while over update since it is not every frame.
My code is like this…
/////3
/////HANDLE GUN FIRE
void determineTrajectory(){
castRay();
}
IEnumerator castRay(){
print("7" + Time.time);
while(btnPressed){
if(Physics.Raycast(bulletRay, out bulletHit, Mathf.Infinity, bulletLayerMask)){
Debug.DrawRay(bPt, bulletTrajectory, Color.green);
print("8");
yield return null;
}
}
}
This issue is that print(“7” + Time.time)" on line 7 is never called. What am I doing wrong?