void playerOrBossEat (objectHealth eaterHealth, GameObject toBeEaten){ objectHealth toBeEatenHealth = toBeEaten.GetComponent<objectHealth> (); int selfHealth = eaterHealth.getHealth (); int otherHealth = toBeEatenHealth.getHealth (); float healthDifference = (float)(selfHealth) / (float)(otherHealth); if (healthDifference <= 0.35f || ((float)(selfHealth)) <= 10f) { if (audioSource != null){ audioSource.PlayOneShot (eatSound, 1f); toBeEaten.GetComponent<ParticleSystem> ().Play (); } Destroy (gameObject); toBeEatenHealth.adjustHealth ((int)((float)selfHealth * healthTransferMultiplier)); if (toBeEaten.tag == "Player") { toBeEaten.GetComponent<Animator> ().SetTrigger ("triggerChomp"); } } else { audioSource.PlayOneShot (hitSound, 1f); float impactDamage = (otherHealth + selfHealth) * impactDamageMultiplier; if (toBeEaten.name == "Pluto" && otherHealth - impactDamage <= 0) { UnityEngine.SceneManagement.SceneManager.LoadScene ("youLost"); } eaterHealth.adjustHealth ((int)- (impactDamage/2)); toBeEatenHealth.adjustHealth ((int)- (impactDamage/2)); // print (eaterHealth.getHealth ()); // print (toBeEatenHealth.getHealth ()); } }
// Update is called once per frame void Update() { float step = speed * Time.deltaTime; float scaleStep = scaleSpeed * Time.deltaTime; transform.position = Vector3.Lerp(transform.position, targetPoint, step); transform.localScale = Vector3.MoveTowards(transform.localScale, targetScale, scaleStep); if (transform.localScale.x == maxScale && transform.position == targetPoint) { StartCoroutine(pauseAndKill()); } float timeNow = Time.time; if (isDoingDamage == true && (timeNow >= (timeSinceEnter + damageRepeatTime))) { GameObject player = GameObject.FindGameObjectWithTag("Player"); objectHealth playerHealth = player.gameObject.GetComponent <objectHealth> (); if (playerHealth.getHealth() - ((int)maxDamage) <= 0) { UnityEngine.SceneManagement.SceneManager.LoadScene("youLost"); } else { playerHealth.adjustHealth((int)-maxDamage); } timeSinceEnter = timeNow; } }
// Use this for initialization void Start() { // get plutos health script plutosHealth = GameObject.Find("Pluto").GetComponent <objectHealth> () as objectHealth; foodsHealth = GetComponentInParent <objectHealth> () as objectHealth; foodRenderer = GetComponent <SkinnedMeshRenderer> (); }
// Use this for initialization void Start() { GameObject player = GameObject.FindGameObjectWithTag("Player"); teleActivate = gameObject.GetComponent <teleportToNewLevel> (); playerHealthScript = player.GetComponent <objectHealth> (); playerSize = playerHealthScript.getHealth(); }
void playerEatsProjectile(objectHealth pluto, GameObject projectile) { objectHealth projectileHealth = projectile.GetComponent <objectHealth> (); audioSource.PlayOneShot(eatSound, 1f); Destroy(projectile); pluto.adjustHealth(projectileHealth.getHealth()); }
// Use this for initialization void Start () { GameObject camera = GameObject.FindGameObjectWithTag("MainCamera"); camControl = camera.GetComponent<cameraController> () as cameraController; chatterBox = GameObject.FindGameObjectWithTag ("chatterBox").GetComponent<chatter> (); GameObject player = GameObject.FindGameObjectWithTag ("Player"); objectHealth = player.GetComponent <objectHealth> (); }
// Use this for initialization void Start() { GameObject camera = GameObject.FindGameObjectWithTag("MainCamera"); camControl = camera.GetComponent <cameraController> () as cameraController; chatterBox = GameObject.FindGameObjectWithTag("chatterBox").GetComponent <chatter> (); GameObject player = GameObject.FindGameObjectWithTag("Player"); objectHealth = player.GetComponent <objectHealth> (); }
// Use this for initialization void Start() { GameObject gCHolder = GameObject.FindGameObjectWithTag("GameController"); if (gCHolder != null) { gameCont = gCHolder.GetComponent <gameController> () as gameController; } GameObject camera = GameObject.FindGameObjectWithTag("MainCamera"); camControl = camera.GetComponent <cameraController> () as cameraController; chatterBox = GameObject.FindGameObjectWithTag("chatterBox").GetComponent <chatter> (); GameObject player = GameObject.FindGameObjectWithTag("Player"); objectHealth = player.GetComponent <objectHealth> (); }
void OnCollisionEnter(Collision other) { objectHealth contacteeHealth = gameObject.GetComponent <objectHealth>(); audioSource = other.gameObject.GetComponent <AudioSource> (); if (gameObject.tag == "Player" && other.gameObject.tag == "projectile") { playerEatsProjectile(contacteeHealth, other.gameObject); } if (other.gameObject.tag == "Player" || other.gameObject.tag == "Boss") { if (other.gameObject.tag == "Player") { maximumSize maxSize = other.gameObject.GetComponent <maximumSize> (); objectHealth plutoHealth = other.gameObject.GetComponent <objectHealth>(); int currentMax = maxSize.getMaxHealth(); int currentHealth = plutoHealth.getHealth(); // Debug.Log ("pluto size: " + currentHealth); if (currentHealth < currentMax) { playerOrBossEat(contacteeHealth, other.gameObject); //other.gameObject.GetComponent<Animator> ().SetTrigger ("triggerHungry"); other.gameObject.GetComponent <Animator> ().SetBool("isHungry", true); } else { other.gameObject.GetComponent <Animator> ().SetBool("isHungry", false); } } else { // Debug.Log ("boss is trying to eat"); playerOrBossEat(contacteeHealth, other.gameObject); //other.gameObject.GetComponent<Animator> ().SetTrigger ("triggerFull"); } } if (other.gameObject.tag == "projectile" && gameObject.tag != "Player") { projectileDoesDamage(contacteeHealth, other.gameObject, other.contacts [0].point, other.contacts [0].normal, other.relativeVelocity); } }
void playerOrBossEat(objectHealth eaterHealth, GameObject toBeEaten) { objectHealth toBeEatenHealth = toBeEaten.GetComponent <objectHealth> (); int selfHealth = eaterHealth.getHealth(); int otherHealth = toBeEatenHealth.getHealth(); float healthDifference = (float)(selfHealth) / (float)(otherHealth); if (healthDifference <= 0.35f || ((float)(selfHealth)) <= 10f) { if (audioSource != null) { audioSource.PlayOneShot(eatSound, 1f); toBeEaten.GetComponent <ParticleSystem> ().Play(); } Destroy(gameObject); toBeEatenHealth.adjustHealth((int)((float)selfHealth * healthTransferMultiplier)); if (toBeEaten.tag == "Player") { toBeEaten.GetComponent <Animator> ().SetTrigger("triggerChomp"); } } else { audioSource.PlayOneShot(hitSound, 1f); float impactDamage = (otherHealth + selfHealth) * impactDamageMultiplier; if (toBeEaten.name == "Pluto" && otherHealth - impactDamage <= 0) { UnityEngine.SceneManagement.SceneManager.LoadScene("youLost"); } eaterHealth.adjustHealth((int)-(impactDamage / 2)); toBeEatenHealth.adjustHealth((int)-(impactDamage / 2)); // print (eaterHealth.getHealth ()); // print (toBeEatenHealth.getHealth ()); } }
void projectileDoesDamage(objectHealth target, GameObject projectile, Vector3 impactPoint, Vector3 impactNormal, Vector3 impactRelVelocity) { // Debug.Log ("projectile made contact with " + gameObject.tag); projectileDamage hit = projectile.GetComponent <projectileDamage> (); int selfSize = target.getHealth(); int hitDamage = (int)(hit.getDamage()); // Debug.Log ("projectile damage eoc: " + hitDamage); if (selfSize > hitDamage) { int foodHealth; // Debug.Log ("hit object health1: " + contacteeHealth.getHealth() + " hit damage: " + hitDamage); int newHealth = target.getHealth() - hitDamage; if (name == "Boss") { newHealth = target.getHealth() - (int)(hitDamage * impactDamageMultiplier); } target.instantiateHealth(newHealth); // Debug.Log ("hit object health2: " + contacteeHealth.getHealth() + "new Health var: " + newHealth); Destroy(projectile); int chunks = (int)(hitDamage / 5); // making boss not emit any food // making boss ANIMATE taking hit!! if (name == "Boss") { chunks = 0; Animator [] animArray = target.GetComponentsInChildren <Animator> (); Animator animActivator = animArray [0]; animActivator.SetTrigger("takeDamage"); audioSource = target.GetComponent <AudioSource> (); audioSource.PlayOneShot(hitSound, 1f); } if (target.CompareTag("food")) { // Debug.Log ("Projectile is trying to look shocked"); Animator [] animArray = target.GetComponentsInChildren <Animator> (); Animator animActivator = animArray [0]; animActivator.SetTrigger("takeDamage"); audioSource = target.GetComponent <AudioSource> (); audioSource.PlayOneShot(takeDamageSound, .7f); } //make food animate for (int i = 0; i < chunks; i++) { foodHealth = (int)(hitDamage / chunks) + 5; // adding fudge 5 points to spawn foods health // Vector3 startPoint = other.contacts [0].point; Vector3 testPoint = impactPoint; Vector3 spawnPosition = impactPoint; GameObject food = foodTypes [Random.Range(0, foodTypes.Length)]; while (impactPoint == spawnPosition) { Vector2 randGen = Random.insideUnitCircle * 2f; Vector3 randPoint = new Vector3(randGen.x, 0, randGen.y); testPoint += randPoint; // Debug.Log (testPoint); bool test = testNewObjectPosition(food, testPoint, (food.transform.localScale.x / 2f)); //assuming base size is 100 here if (test) { spawnPosition = testPoint; } } Quaternion spawnRotation = Random.rotation; GameObject newFood = (GameObject)Instantiate(food, spawnPosition, spawnRotation); newFood.GetComponent <objectHealth> ().instantiateHealth(foodHealth); // Vector3 direction = other.contacts [0].normal; Vector3 dirRandomizor = Random.insideUnitSphere * 2f; Vector3 velocityRB = impactNormal + dirRandomizor + impactRelVelocity; Rigidbody foodRB = newFood.GetComponent <Rigidbody> (); foodRB.AddForce(-velocityRB * 8f); } } if (selfSize <= hitDamage) { Destroy(gameObject); Destroy(projectile); } }
void projectileDoesDamage (objectHealth target, GameObject projectile, Vector3 impactPoint, Vector3 impactNormal, Vector3 impactRelVelocity){ // Debug.Log ("projectile made contact with " + gameObject.tag); projectileDamage hit = projectile.GetComponent<projectileDamage> (); int selfSize = target.getHealth (); int hitDamage = (int)(hit.getDamage ()); // Debug.Log ("projectile damage eoc: " + hitDamage); if (selfSize > hitDamage) { int foodHealth; // Debug.Log ("hit object health1: " + contacteeHealth.getHealth() + " hit damage: " + hitDamage); int newHealth = target.getHealth () - hitDamage; if (name == "Boss") { newHealth = target.getHealth () - (int)(hitDamage * impactDamageMultiplier); } target.instantiateHealth (newHealth); // Debug.Log ("hit object health2: " + contacteeHealth.getHealth() + "new Health var: " + newHealth); Destroy (projectile); int chunks = (int)(hitDamage / 5); // making boss not emit any food // making boss ANIMATE taking hit!! if (name == "Boss") { chunks = 0; Animator [] animArray = target.GetComponentsInChildren<Animator> (); Animator animActivator = animArray [0]; animActivator.SetTrigger ("takeDamage"); audioSource = target.GetComponent<AudioSource> (); audioSource.PlayOneShot (hitSound, 1f); } if (target.CompareTag ("food")) { // Debug.Log ("Projectile is trying to look shocked"); Animator [] animArray = target.GetComponentsInChildren<Animator> (); Animator animActivator = animArray [0]; animActivator.SetTrigger ("takeDamage"); audioSource = target.GetComponent<AudioSource> (); audioSource.PlayOneShot (takeDamageSound, .7f); } //make food animate for (int i = 0; i < chunks; i++) { foodHealth = (int)(hitDamage / chunks) + 5; // adding fudge 5 points to spawn foods health // Vector3 startPoint = other.contacts [0].point; Vector3 testPoint = impactPoint; Vector3 spawnPosition = impactPoint; GameObject food = foodTypes [Random.Range (0, foodTypes.Length)]; while (impactPoint == spawnPosition) { Vector2 randGen = Random.insideUnitCircle * 2f; Vector3 randPoint = new Vector3 (randGen.x, 0, randGen.y); testPoint += randPoint; // Debug.Log (testPoint); bool test = testNewObjectPosition (food, testPoint, (food.transform.localScale.x / 2f)); //assuming base size is 100 here if (test) { spawnPosition = testPoint; } } Quaternion spawnRotation = Random.rotation; GameObject newFood = (GameObject)Instantiate (food, spawnPosition, spawnRotation); newFood.GetComponent<objectHealth> ().instantiateHealth (foodHealth); // Vector3 direction = other.contacts [0].normal; Vector3 dirRandomizor = Random.insideUnitSphere * 2f; Vector3 velocityRB = impactNormal + dirRandomizor + impactRelVelocity; Rigidbody foodRB = newFood.GetComponent<Rigidbody> (); foodRB.AddForce (-velocityRB * 8f); } } if (selfSize <= hitDamage) { Destroy (gameObject); Destroy (projectile); } }
void playerEatsProjectile (objectHealth pluto, GameObject projectile){ objectHealth projectileHealth = projectile.GetComponent<objectHealth> (); audioSource.PlayOneShot (eatSound, 1f); Destroy (projectile); pluto.adjustHealth (projectileHealth.getHealth ()); }
// Use this for initialization void Start () { GameObject player = GameObject.FindGameObjectWithTag ("Player"); teleActivate = gameObject.GetComponent<teleportToNewLevel> (); playerHealthScript = player.GetComponent<objectHealth> (); playerSize = playerHealthScript.getHealth (); }
// Use this for initialization void Start () { // get plutos health script plutosHealth = GameObject.Find ("Pluto").GetComponent<objectHealth> () as objectHealth; foodsHealth = GetComponentInParent<objectHealth> () as objectHealth; foodRenderer = GetComponent<SkinnedMeshRenderer> (); }