Exemplo n.º 1
0
	void OnCollisionEnter(Collision collision)
	{
		if (collision.gameObject.tag == "Enemy")
		{

			//Shadow Morties avoid all enemy objects like flargo, prax, mermaid (smaller units) but not goob 
			if (collision.collider.gameObject.name.Contains("flargo")) {
				Physics.IgnoreCollision(collision.collider.gameObject.GetComponent<Collider>(),GetComponent<Collider>());
			}
			if (collision.collider.gameObject.name.Contains("prax"))
			{
				Physics.IgnoreCollision(collision.collider.gameObject.GetComponent<Collider>(),GetComponent<Collider>());
			}
			if (collision.collider.gameObject.name.Contains("mermaid"))
			{
				Physics.IgnoreCollision(collision.collider.gameObject.GetComponent<Collider>(),GetComponent<Collider>());
			}

			if (collision.collider.gameObject.name.Contains("goob"))
			{
				goobObj = collision.collider.gameObject.GetComponent<goobScript>();
				goobObj.current_health -= damage;
				current_health -= goobObj.damage;

				unitManagerScript.displayFlash (goobObj.transform.position, this.transform.position);
				goobObj.transform.position += new Vector3 (0.5f, 0f, 0f);
				this.transform.position += new Vector3 (-0.5f, 0f, 0f);

				Dead();

				if (goobObj.current_health <= 0) {
					Destroy(collision.collider.gameObject);
					unitManagerScript.enemyUnitKilled();
					unitManagerScript.rewardGold (35);
				}

			}

		}
		//When collided with enemy tower, enemy tower disappears for now 
		if (collision.collider.gameObject.name.Contains("Enemy Tower"))
		{
			tempScript = collision.collider.gameObject.GetComponent<EnemyTowerScript>();
			Debug.Log("Attacked enemy tower!");
			this.transform.position += new Vector3 (-0.5f, 0f, 0f);
			Destroy(gameObject);
			unitManagerScript.displayFlash (this.transform.position, this.transform.position);
			unitManagerScript.rewardGold (50);
		}
		unitManagerScript.playBounce ();
	}
Exemplo n.º 2
0
	void OnCollisionEnter(Collision collision)
	{
		if (collision.gameObject.tag == "Enemy")
		{
			if (collision.collider.gameObject.name.Contains("flargo")) {
				flargoObj = collision.collider.gameObject.GetComponent<flargoScript>();

				flargoObj.current_health -= damage * 2;
				current_health -= flargoObj.damage;

				unitManagerScript.displayFlash (flargoObj.transform.position, this.transform.position);
				flargoObj.transform.position += new Vector3 (0.5f, 0f, 0f);
				this.transform.position += new Vector3 (-0.5f, 0f, 0f);

				Dead ();
				if (flargoObj.current_health <= 0) {
					Destroy(collision.collider.gameObject);
					unitManagerScript.enemyUnitKilled();
					unitManagerScript.rewardGold (5);
				}

			}
			if (collision.collider.gameObject.name.Contains("prax"))
			{
				praxObj = collision.collider.gameObject.GetComponent<praxScript>();
				praxObj.current_health -= damage * 2; //karate is better against prax enemy unity
				current_health -= praxObj.damage;

				unitManagerScript.displayFlash (praxObj.transform.position, this.transform.position);
				praxObj.transform.position += new Vector3 (0.5f, 0f, 0f);
				this.transform.position += new Vector3 (-0.5f, 0f, 0f);

				Dead();
				if (praxObj.current_health <= 0) {
					Destroy(collision.collider.gameObject);
					unitManagerScript.enemyUnitKilled();
					unitManagerScript.rewardGold (10);
				}

			}
			if (collision.collider.gameObject.name.Contains("mermaid"))
			{
				mermaidObj = collision.collider.gameObject.GetComponent<mermaidScript>();
				mermaidObj.current_health -= damage * 2; //karate is better against mermaid enemy unity
				current_health -= mermaidObj.damage;

				unitManagerScript.displayFlash (mermaidObj.transform.position, this.transform.position);
				mermaidObj.transform.position += new Vector3 (0.5f, 0f, 0f);
				this.transform.position += new Vector3 (-0.5f, 0f, 0f);

				Dead();

				if (mermaidObj.current_health <= 0) {
					Destroy(collision.collider.gameObject);
					unitManagerScript.enemyUnitKilled();
					unitManagerScript.rewardGold (10);
				}

			}

			if (collision.collider.gameObject.name.Contains("goob"))
			{
				goobObj = collision.collider.gameObject.GetComponent<goobScript>();
				goobObj.current_health -= damage;
				current_health -= goobObj.damage;

				unitManagerScript.displayFlash (goobObj.transform.position, this.transform.position);
				goobObj.transform.position += new Vector3 (0.5f, 0f, 0f);
				this.transform.position += new Vector3 (-0.5f, 0f, 0f);

				Dead();

				if (goobObj.current_health <= 0) {
					Destroy(collision.collider.gameObject);
					unitManagerScript.enemyUnitKilled();
					unitManagerScript.rewardGold (35);
				}

			}
		}
		//When collided with enemy tower, enemy tower disappears for now 
		if (collision.collider.gameObject.name.Contains("Enemy Tower"))
		{
			tempScript = collision.collider.gameObject.GetComponent<EnemyTowerScript>();
			this.transform.position += new Vector3 (-0.5f, 0f, 0f);
			Destroy(gameObject);
			unitManagerScript.displayFlash (this.transform.position, this.transform.position);
			unitManagerScript.rewardGold (35);
		}
			
		unitManagerScript.playBounce ();
			
	}