void counterAttack( unitStatScript otherStats) { angle += 180; otherStats.angle = angle; var shotTransform = Instantiate(shotPrefab) as Transform; // Assign position shotTransform.position = otherStats.transform.position; // The is enemy property ShotScript shot = shotTransform.gameObject.GetComponent<ShotScript>(); if (shot != null) { shot.isSplash = false; shot.timeDestroy = otherStats.range * 0.5f; shot.shotRange = otherStats.range; shot.teamNumber = otherStats.playerOwner; shot.parentsStats = otherStats; shot.angle = angle; shot.isCounter = true; //assign a randomized damage value based off of unit's attack shot.attackPower = Random.Range(0, otherStats.attack); } // Make the weapon shot always towards it moveScript2 move = shotTransform.gameObject.GetComponent<moveScript2>(); if (move != null) { move.direction = new Vector2(direction.x * -1, direction.y * -1); // towards in 2D space is the right of the sprite } }
void counterAttack(unitStatScript otherStats) { angle += 180; otherStats.angle = angle; var shotTransform = Instantiate(shotPrefab) as Transform; // Assign position shotTransform.position = otherStats.transform.position; // The is enemy property ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isSplash = false; shot.timeDestroy = otherStats.range * 0.5f; shot.shotRange = otherStats.range; shot.teamNumber = otherStats.playerOwner; shot.parentsStats = otherStats; shot.angle = angle; shot.isCounter = true; //assign a randomized damage value based off of unit's attack shot.attackPower = Random.Range(0, otherStats.attack); } // Make the weapon shot always towards it moveScript2 move = shotTransform.gameObject.GetComponent <moveScript2>(); if (move != null) { move.direction = new Vector2(direction.x * -1, direction.y * -1); // towards in 2D space is the right of the sprite } }
void Start() { //initialize russian units unit_RussianAT = GameObject.Find("unit_RussianAT"); unit_RussianBomber = GameObject.Find("unit_RussianBomber"); unit_RussianCannon = GameObject.Find("unit_RussianCannon"); unit_RussianFighter = GameObject.Find("unit_RussianFighter"); unit_RussianSniper = GameObject.Find("unit_RussianSniper"); unit_RussianSquad = GameObject.Find("unit_RussianSquad"); unit_t28 = GameObject.Find("unit_t-28"); unit_t34 = GameObject.Find("unit_t-34"); unit_t60 = GameObject.Find("unit_t-60"); //initialize german units unit_Flak30 = GameObject.Find("unit_Flak30"); unit_GermanAT = GameObject.Find("unit_GermanAT"); unit_GermanBomber = GameObject.Find("unit_GermanBomber"); unit_GermanFighter = GameObject.Find("unit_GermanFighter"); unit_GermanSniper = GameObject.Find("unit_GermanSniper"); unit_GermanSquad = GameObject.Find("unit_GermanSquad"); unit_panther = GameObject.Find("unit_panther"); unit_Panzer4 = GameObject.Find("unit_Panzer4"); unit_Wirbelwind = GameObject.Find("unit_Wirbelwind"); GameObject gameControllerObject = GameObject.FindWithTag("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent <GameController>(); } parentStats = transform.parent.GetComponent <unitStatScript> (); }
public void pickedObject(unitStatScript pickedObject) { for (int i = 0; i < unitCounter.Length; i++) { if(unitCounter[i].GetComponent<unitStatScript>() != pickedObject) { unitCounter[i].GetComponent<unitStatScript>().picked = false; } } }
public void pickedObject(unitStatScript pickedObject) { for (int i = 0; i < unitCounter.Length; i++) { if (unitCounter[i].GetComponent <unitStatScript>() != pickedObject) { unitCounter[i].GetComponent <unitStatScript>().picked = false; } } }
void Start() { parentsStats = transform.GetComponent <unitStatScript> (); teamNumber = parentsStats.playerOwner; GameObject gameControllerObject = GameObject.FindWithTag("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent <GameController>(); } }
void OnTriggerEnter2D(Collider2D otherCollider) { if (isCauseDamage == true) { //this is where the damage calculations take place. otherStats is the enemy unit's stats unitStatScript otherStats = otherCollider.gameObject.GetComponent <unitStatScript> (); if (otherStats != null && otherStats.playerOwner == 1 && parentShot.teamNumber == 2) { if ((otherStats.isTank && parentShot.parentsStats.canShootTank) || (otherStats.isPlane && parentShot.parentsStats.canShootPlane) || (otherStats.isInfantry && parentShot.parentsStats.canShootInfantry)) { //deals damage equal to this attack power minus arandom value of defense. int tempDefense = Random.Range(0, otherStats.defense); if (attackPower > tempDefense) { otherStats.health -= (attackPower - tempDefense); } SpecialEffectsHelper.Instance.Explosion(transform.position); //if(!isCounter) // counterAttack (otherStats); Debug.Log("Collide splash"); isCauseDamage = false; //Destroy (gameObject); } } else if (otherStats != null && otherStats.playerOwner == 2 && parentShot.teamNumber == 1) { if ((otherStats.isTank && parentShot.parentsStats.canShootTank) || (otherStats.isPlane && parentShot.parentsStats.canShootPlane) || (otherStats.isInfantry && parentShot.parentsStats.canShootInfantry)) { //deals damage equal to this attack power minus arandom value of defense. int tempDefense = Random.Range(0, otherStats.defense); if (attackPower > tempDefense) { otherStats.health -= (attackPower - tempDefense); } SpecialEffectsHelper.Instance.Explosion(transform.position); //if(!isCounter) // counterAttack (otherStats); //Destroy (gameObject); Debug.Log("Collide splash"); isCauseDamage = false; } } } }
// Use this for initialization void Start() { grandParentStats = transform.parent.parent.parent.GetComponent <unitStatScript> (); GameObject gameControllerObject = GameObject.FindWithTag("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent <GameController>(); } x1 = this.transform.position.x; y1 = this.transform.position.y; if (x1 >= grandParentStats.transform.position.x) { angle = Mathf.Rad2Deg * Mathf.Atan((y1 - grandParentStats.transform.position.y) / (x1 - grandParentStats.transform.position.x)); angle -= 90; } else { angle = Mathf.Rad2Deg * Mathf.Atan((y1 - grandParentStats.transform.position.y) / (x1 - grandParentStats.transform.position.x)); angle += 90; } }
void OnTriggerEnter2D(Collider2D otherCollider) { stone_script stone = otherCollider.gameObject.GetComponent <stone_script> (); if (stone != null) { //Debug.Log ("Collide stone!"); SpecialEffectsHelper.Instance.Explosion(transform.position); Destroy(gameObject); } //this is where the damage calculations take place. otherStats is the enemy unit's stats //unitStatScript otherStats = otherCollider.gameObject.GetComponent<unitStatScript> (); hexMove otherHexMove = otherCollider.gameObject.GetComponent <hexMove> (); if (otherHexMove != null) { unitStatScript otherStats = otherHexMove.transform.parent.GetComponent <unitStatScript> (); if (otherStats != null && otherStats.playerOwner == 1 && teamNumber == 2) { if ((otherStats.isTank && parentsStats.canShootTank) || (otherStats.isPlane && parentsStats.canShootPlane) || (otherStats.isInfantry && parentsStats.canShootInfantry)) { //deals damage equal to this attack power minus arandom value of defense. int tempDefense = Random.Range(0, otherStats.defense); if (attackPower > tempDefense) { damageDealt = attackPower - tempDefense; otherStats.statText.color = Color.red; otherStats.health -= damageDealt; } SpecialEffectsHelper.Instance.Explosion(transform.position); if (!isCounter) { counterAttack(otherStats); } if (isSplash == true) { StartCoroutine(waitAndCall()); } else { Destroy(gameObject); } } } else if (otherStats != null && otherStats.playerOwner == 2 && teamNumber == 1) { if ((otherStats.isTank && parentsStats.canShootTank) || (otherStats.isPlane && parentsStats.canShootPlane) || (otherStats.isInfantry && parentsStats.canShootInfantry)) { //deals damage equal to this attack power minus arandom value of defense. int tempDefense = Random.Range(0, otherStats.defense); if (attackPower > tempDefense) { damageDealt = attackPower - tempDefense; otherStats.statText.color = Color.red; otherStats.health -= damageDealt; } SpecialEffectsHelper.Instance.Explosion(transform.position); if (!isCounter) { counterAttack(otherStats); } if (isSplash == true) { StartCoroutine(waitAndCall()); } else { Destroy(gameObject); } } } } }
void Start() { parentsStats = transform.GetComponent<unitStatScript> (); teamNumber = parentsStats.playerOwner; GameObject gameControllerObject = GameObject.FindWithTag ("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent <GameController>(); } }
// Use this for initialization void Start() { grandParentStats = transform.parent.parent.parent.GetComponent<unitStatScript> (); GameObject gameControllerObject = GameObject.FindWithTag ("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent <GameController>(); } x1 = this.transform.position.x; y1 = this.transform.position.y; if (x1 >= grandParentStats.transform.position.x) { angle = Mathf.Rad2Deg * Mathf.Atan ((y1 - grandParentStats.transform.position.y) / (x1 - grandParentStats.transform.position.x)); angle -= 90; } else { angle = Mathf.Rad2Deg * Mathf.Atan ((y1 - grandParentStats.transform.position.y) / (x1 - grandParentStats.transform.position.x)); angle += 90; } }
void Start() { //initialize russian units unit_RussianAT = GameObject.Find ("unit_RussianAT"); unit_RussianBomber = GameObject.Find ("unit_RussianBomber"); unit_RussianCannon = GameObject.Find ("unit_RussianCannon"); unit_RussianFighter = GameObject.Find ("unit_RussianFighter"); unit_RussianSniper = GameObject.Find ("unit_RussianSniper"); unit_RussianSquad = GameObject.Find ("unit_RussianSquad"); unit_t28 = GameObject.Find("unit_t-28"); unit_t34 = GameObject.Find("unit_t-34"); unit_t60 = GameObject.Find("unit_t-60"); //initialize german units unit_Flak30 = GameObject.Find ("unit_Flak30"); unit_GermanAT = GameObject.Find ("unit_GermanAT"); unit_GermanBomber = GameObject.Find ("unit_GermanBomber"); unit_GermanFighter = GameObject.Find ("unit_GermanFighter"); unit_GermanSniper = GameObject.Find ("unit_GermanSniper"); unit_GermanSquad = GameObject.Find ("unit_GermanSquad"); unit_panther = GameObject.Find ("unit_panther"); unit_Panzer4 = GameObject.Find ("unit_Panzer4"); unit_Wirbelwind = GameObject.Find ("unit_Wirbelwind"); GameObject gameControllerObject = GameObject.FindWithTag ("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent <GameController>(); } parentStats = transform.parent.GetComponent<unitStatScript> (); }