/** * Called when a tower bullet strikes a nutrient */ public void OnBulletCollision() { Absorb(); // call the absorb function // emit effect particles unless the nutrient was fat1 if (m_BodyColor != Fats1Color) { foodBlobEffectParticles = (FoodBlobEffectParticles)Instantiate(effectParticleParent); // create the particles path = this.transform.parent.gameObject.GetComponent <FollowITweenPath> (); // add particles to the path float pathPos = path.pathPosition; // set the position the particles are on the path foodBlobEffectParticles.setPathPosition(pathPos); foodBlobEffectParticles.createParticles(m_BodyColor); // set the color of the emitted particles foodBlobEffectParticles.transform.position = gameObject.transform.parent.position; foodBlobEffectParticles.transform.rotation = gameObject.transform.parent.rotation; } if (m_BodyColor == Fats1Color) // if the color of the nutrient was fat1 we need to turn it white { nutrientManager.ChangeColor(this, Color.white); // changes the color ((Behaviour)gameObject.GetComponent("Halo")).enabled = true; // adds a slight glow effect to the nutrient } else // if the nutrient was not fat1 we handle getting ready to destroy the nutrient { ((Behaviour)gameObject.GetComponent("Halo")).enabled = false; // make sure the halo is not enabled isDead = true; // set the flag to indicate the nutrient is dead m_TargetColor = new Color(92f / 255f, 64f / 255f, 51f / 255f); // set the new target color for fading IsTargetted = true; // set the isTargetted flag so a tower doesn't try to shoot at this nutrient again } m_TrueColor = m_BodyColor; // set this to help with fading }
/** * function that handles spawning the food blob */ private void SpawnBlob() { // instantiate a blob GameObject blob = (GameObject)Instantiate(SpawnType, SpawnPoint, Quaternion.identity); // add an itween path to the blob path = blob.GetComponent <FollowITweenPath>(); path.nutrientSpeed = speed; // set the food blob's speed on the path blobScript = blob.GetComponent <FoodBlob>(); // get the script on the foodblob // call the function to generateenzymes on the blob blobScript.GenerateEnzymes(minNutrients, maxNutrients, availableColors); }
/** * function to set the path position where the effect particles should start following the path */ public void setPathPosition(float position) { path = gameObject.GetComponent <FollowITweenPath> (); // get the itween path script path.pathPosition = position; // set the path position }