// Use this for initialization void Start() { numberOfFriendlyUnits = 0; numberOfEnemyUnits = 0; health = 50; fightingUnitCost = 5; fighting = false; spawnSpot = new Vector3(transform.position.x - (transform.GetComponent <MeshRenderer>().bounds.extents.x * 1.5f), transform.position.y, transform.position.z - (transform.GetComponent <MeshRenderer>().bounds.extents.z *1.005f)); scaleOfWorld = GameObject.Find("Scaler").transform.localScale.x; x_offset = 0; z_offset = -15f * scaleOfWorld; if (this.name == "Cube_A") { enemyBase = GameObject.Find("Cube_B").transform; usableMines = GameObject.Find("Mines_A"); summoningZone = GameObject.Find("SummoningZone_A").transform; } else if (this.name == "Cube_B") { enemyBase = GameObject.Find("Cube_A").transform; usableMines = GameObject.Find("Mines_B"); summoningZone = GameObject.Find("SummoningZone_B").transform; } enemyCastleScript = enemyBase.GetComponent <CastleClick>(); canvasControllerScript = GameObject.FindObjectOfType <Canvas>().GetComponent <CanvasController>(); }
void OnCollisionStay(Collision collision) { if (collision.collider.tag == "Base") { if (!collision.gameObject.Equals(transform.parent)) { ultimateDestinationReached = true; moving = false; fighting = true; if (animator) { animator.SetBool("moving", false); animator.SetBool("fighting", true); } timer += Time.deltaTime; if (timer > 2.5f) { enemyScriptCastleClick = collision.collider.GetComponent <CastleClick>(); enemyScriptCastleClick.TakeDamage(damageAmount); Debug.Log("damaged castle by: " + damageAmount); timer = 0; } } } else if (collision.collider.tag == "Fighter") { if (!isSibling(collision.collider.gameObject)) { moving = false; fighting = true; if (animator) { animator.SetBool("moving", false); animator.SetBool("fighting", true); } rigidbodyy.constraints = RigidbodyConstraints.FreezeAll; timer += Time.deltaTime; if (timer > 2.5f && (inArena || ultimateDestinationReached)) { enemyScriptFighterManager = collision.collider.gameObject.GetComponent <FighterManager>(); enemyScriptFighterManager.takeDamage(damageAmount); Debug.Log("damaged other fighter by " + damageAmount); timer = 0; } } else { //rigidbodyy.AddForce(Vector3.forward * 10, ForceMode.Force); transform.LookAt(destination); rigidbodyy.AddTorque(Vector3.forward * 2, ForceMode.Impulse); } } }
public void SetEnemyBase(Transform e) { targetEnemyBase = e; //If you have an enemy, parent is already assigned. parentScriptCastleClick = transform.parent.GetComponent <CastleClick>(); }