//-------------------------------- // 3 - Shooting from another script //-------------------------------- /// <summary> /// Create a new projectile if possible /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Create a new shot var shotTransform = Instantiate(shotPrefab) as Transform; // Assign position shotTransform.position = transform.position; // The is enemy property //ShotScript shot = shotTransform.gameObject.GetComponent<ShotScript>(); //if (shot != null) //{ // shot.isEnemyShot = isEnemy; //} // Make the weapon shot always towards it moveScript2 move = shotTransform.gameObject.GetComponent <moveScript2>(); if (move != null) { move.direction = this.transform.up; // 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 } }
//-------------------------------- // 3 - Shooting from another script //-------------------------------- /// Create a new projectile if possible public void Attack(bool isEnemy, bool counter) { if (!parentsStats.hasAttacked) { parentsStats.hasAttacked = true; // Create a new shot var shotTransform = Instantiate(shotPrefab) as Transform; // Assign position shotTransform.position = transform.position; // The is enemy property ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { if (parentsStats.isTank) { audio.PlayOneShot(tankshot); } else if (parentsStats.isPlane) { audio.PlayOneShot(planeshot); } else if (parentsStats.isInfantry) { audio.PlayOneShot(infantryshot); } shot.isSplash = hasSplash; shot.timeDestroy = timeDestroy; shot.shotRange = parentsStats.rangeClicked; //give it the range of the ring that was clicked on shot.teamNumber = teamNumber; shot.parentsStats = parentsStats; shot.angle = angleF; shot.direction = this.transform.up; if (counter) { shot.isCounter = true; } //assign a randomized damage value based off of unit's attack shot.attackPower = Random.Range(0, parentsStats.attack); } // Make the weapon shot always towards it moveScript2 move = shotTransform.gameObject.GetComponent <moveScript2>(); if (move != null) { move.direction = this.transform.up; // towards in 2D space is the right of the sprite } } }