public IEnumerator FlipFood(Transform main, Transform mdel, Vector3 toPos, float dur, Food_O food) //when the player flips a food object { isMoving = true; food.ChangeDrag(0); float counter = 0; angle += 180; float a = 0; food.DisablePhysics(food.transform); Vector3 startPos = main.position; isMoving = true; while (counter < dur) //moving up { counter += Time.deltaTime; main.position = Vector3.Lerp(startPos, toPos, counter / dur); yield return(null); } while (a < 180) //then rotating { mdel.Rotate(Vector3.forward, 10); a += 10; yield return(null); } food.EnablePhysics(food.transform); //allowing gravity to take it down float dist = .1f; float cal = Mathf.Sqrt(dist / -(Physics.gravity.y / 2)); yield return(new WaitForSeconds(cal)); //only changing the drag after the food has finished falling food.ChangeDrag(3); isMoving = false; }
public IEnumerator RestockFood(GameObject foodType, float time) { List <PlaceMarker> markers = GetComponentsInChildren <PlaceMarker>().ToList(); for (int i = 0; i < markers.Count; i++) { if (markers[i].transform.parent.CompareTag("Food")) { continue; } if (!markers[i].GetOccupation()) { GameObject food = Instantiate(foodType, markers[i].transform.position, markers[i].transform.rotation); Food_O f = food.GetComponent <Food_O>(); f.SetMarker(markers[i]); f.EnablePhysics(transform); f.ChangeDrag(f.defaultDrag); f.SetOnSurface(true); f.SetFreshness(true); markers[i].SetOccupation(true); ListOfFood().Add(f); MarkerList().Remove(markers[i]); yield return(new WaitForSeconds(time)); } } }