//External access to the coroutine to start harvesting a single blob of blood. //public void Consume(HarvesterScript harvester, float HarvestAmount) //{ // if(bloodCount > 0) // StartCoroutine(SendBloodProjToHarvester(harvester, HarvestAmount)); //} public void Consume(PlayerHarvester harvester, float HarvestAmount) { if (bloodCount > 0) { StartCoroutine(SendBloodProjToHarvester(harvester, HarvestAmount)); } }
private void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { GameManager.instance.lives -= other.GetComponentInParent <EnemyScript>().livesCost; Destroy(other.transform.parent.gameObject); } if (other.tag == "Minion") { PlayerHarvester minion = other.GetComponent <PlayerHarvester>(); if (minion != null) { GameManager.instance.blood += minion.bloodHold; minion.bloodHold = 0; minion.Heal(); } } }
//private IEnumerator StartFading() //{ // FadingStarted = true; // Material material = GetComponentInChildren<Renderer>().material; // // float t = 0.0f; // float dt = 0.05f; // float dt2 = 0.01f; // float alpha = 1.0f; // // for (int i = 0; i < 5; i++) // { // t = 0.0f; // dt = 0.05f; // dt2 = 0.01f; // alpha = 1.0f; // // do // { // alpha = Mathf.Lerp(1.0f, 0.0f, t); // material.SetFloat("Alpha", alpha); // // t += dt * Time.deltaTime; // dt += dt2; // // yield return new WaitForEndOfFrame(); // } while (alpha > 0.0f); // // do // { // alpha = Mathf.Lerp(1.0f, 0.0f, t); // material.SetFloat("Alpha", alpha); // // t -= dt * Time.deltaTime; // dt += dt2; // // yield return new WaitForEndOfFrame(); // } while (alpha < 1.0f); // } // // do // { // alpha = Mathf.Lerp(1.0f, 0.0f, t); // material.SetFloat("Alpha", alpha); // // t += dt * Time.deltaTime; // dt += dt2; // // yield return new WaitForEndOfFrame(); // } while (alpha > 0.0f); // // Destroy(gameObject); // // yield return null; //} private IEnumerator SendBloodProjToHarvester(PlayerHarvester consumer, float bloodTransferAmount) { //Create the blob of blood GameObject blood = GameObject.Instantiate(bloodSpherePrefab, transform.position, Quaternion.identity); blood.transform.localScale = blood.transform.localScale * bloodTransferAmount; //Set up the inital variables float t = 0.0f; float dt = 0.05f; float dt2 = 0.01f; Vector3 inital = blood.transform.position; float bloodContents = Mathf.Min(bloodTransferAmount, bloodCount); //Reduce this blood pool of the amount the blob is carrying. bloodCount = Mathf.Clamp(bloodCount - bloodTransferAmount, 0, maxBlood); //Add to a list for clean up myBloodProj.Add(blood); //In sync with frames, lerp the position of the blob to the consumer while (blood.transform.position != consumer.transform.position) { blood.transform.position = Vector3.Lerp(inital, consumer.transform.position, t); t += dt * Time.deltaTime; dt += dt2; yield return(new WaitForEndOfFrame()); } //Blob has arrived andso we give them the blood contents. consumer.bloodHold += bloodContents; //No need to remember for clean up myBloodProj.Remove(blood); //Clean up ourselfs Destroy(blood); //Done yield return(null); }