//-------------------------------- // 3 - Стрельба из другого скрипта //-------------------------------- /// <summary> /// Создайте новый снаряд, если это возможно /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Создайте новый выстрел var shotTransform = Instantiate(shotPrefab) as Transform; // Определите положение shotTransform.position = transform.position; // Свойство врага ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // Сделайте так, чтобы выстрел всегда был направлен на него MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; // в двухмерном пространстве это будет справа от спрайта } } }
//-------------------------------- // 3 - Tirer depuis un autre script //-------------------------------- /// <summary> /// Création d'un projectile si possible /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Création d'un objet copie du prefab var shotTransform = Instantiate(shotPrefab) as Transform; // Position shotTransform.position = transform.position; // Propriétés du script ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // On saisit la direction pour le mouvement MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; // ici la droite sera le devant de notre objet } } }
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 MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.gameObject.GetComponent <PlayerScript>().movementLeft ? new Vector2(-1, 0) : new Vector2(1, 0); shotTransform.GetComponent <SpriteRenderer>().flipX = move.direction.x < 0; } } }
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 OnTriggerEnter2D(Collider2D collider) { // Est-ce un tir ? ShotScript shot = collider.gameObject.GetComponent <ShotScript>(); if (shot != null) { // Tir allié if (shot.isEnemyShot != isEnemy) { hp -= shot.damage; // Destruction du projectile // On détruit toujours le gameObject associé // sinon c'est le script qui serait détruit avec ""this"" Destroy(shot.gameObject); if (hp <= 0) { // Destruction ! Destroy(gameObject); } } } }
/// <summary> /// Creates a shot based on the position and rotation of the weapon /// </summary> /// <param name="isEnemy">Whether or not the shot is an enemy's shot</param> public void Shoot(bool isEnemy) { //If the shot cooldown has reached 0 if (shotCooldown <= 0f) { //Reset the shot cooldown shotCooldown = shotRate; //Create a new shot at the position of the weapon var shot = Instantiate(shotPrefab) as Transform; shot.position = new Vector3(transform.position.x, transform.position.y - 0.04f, transform.position.z); shot.eulerAngles = transform.eulerAngles; ShotScript shotScript = shot.gameObject.GetComponent <ShotScript>(); //Sets whether or not the shot is an enemy's or the player's if (shot != null) { shotScript.enemyShot = isEnemy; } //Makes sure the shot moves right relative to the weapon MoveScript movement = shot.gameObject.GetComponent <MoveScript>(); if (movement != null) { movement.direction = shot.transform.right; } } }
void OnTriggerEnter2D(Collider2D otherCollider) { // Check if the lever was hit by a projectile ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { Destroy(shot.gameObject, 0.5f); Destroy(otherCollider.gameObject.GetComponent <MoveScript>()); otherCollider.isTrigger = false; //otherCollider.gameObject.GetComponent<Rigidbody2D>().gravityScale = 1.0f; this.activated = !this.activated; if (spriteRenderer == null) { spriteRenderer = GetComponent <SpriteRenderer>(); } if (spriteRenderer.sprite == sprite1) { spriteRenderer.sprite = sprite2; } else { spriteRenderer.sprite = sprite1; } } }
void OnTriggerEnter2D(Collider2D otherCollider) { // Is this a shot? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null && !immuneToDamage && !dead) { // Avoid friendly fire, apply ranged immunity if ((!(immuneToShots && !shot.isMelee)) && shot.team != team) { Damage(shot.damage); shot.onImpact(gameObject.transform); } } else { //Is this the activator object? ActivatorScript activator = otherCollider.gameObject.GetComponent <ActivatorScript>(); if (activator != null && !manualActivation && !active) { if (activator.isActivator) { active = true; } } } }
void OnTriggerEnter2D(Collider2D otherCollider) { //is this a standard shot? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { //no friendly fire if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); //Destroy the shot Destroy(shot.gameObject); //target game object so we don't remove the script - again ... lol } } //is this a rock shot? RockShotScript rockShot = otherCollider.gameObject.GetComponent <RockShotScript>(); if (rockShot != null) { //no friendly fire if (rockShot.isEnemyShot != isEnemy) { Damage(rockShot.damage); //Destroy the shot Destroy(rockShot.gameObject); //target game object so we don't remove the script - again ... lol } } }
public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = ShootingRate; if (ShootSound != null) { audio.PlayOneShot(ShootSound); } var shotTransform = Instantiate(ShotPrefab) as Transform; shotTransform.position = transform.position; ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript> (); if (shot != null) { shot.IsEnemyShot = isEnemy; } MoveScript move = shotTransform.gameObject.GetComponent <MoveScript> (); if (move != null) { move.Direction = this.transform.right; move.Speed = BulletSpeed; } } }
//--------------------------------------- // 3 - Стрельба из другого скрипта //--------------------------------------- ///<summary /// Создайте новый снаряд, если это возможно ///</summaru> public void Attack(bool isEnemy) { if (CanAttack) { //просто сохрани)) shootCooldown = shootingRate; // новый выстрел var shotTransform = Instantiate(shortPrefab) as Transform; // определение местоположения shotTransform.position = transform.position; // свойство врага ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // Cделать так, чтобы выстрел всегда был направлен на него MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; // справо от спрайта } } }
public void Attack(bool isEnemy) { if (CanAttack) { //reset cooldown shootCooldown = shootingRate; //create new shot var shotTransform = Instantiate(shotPrefab) as Transform; // assign position shotTransform.position = transform.position; //handly isEnemy ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = transform.right; } } }
//-------------------------------- // 3 - Shooting from another script //-------------------------------- /// <summary> /// Create a new projectile if possible /// </summary> public void Attack(int shooterId, bool facingRight) { if (CanAttack) { shootCooldown = shootingRate; // Create a new shot var shotTransform = Instantiate(shotPrefab) as Transform; // if(!facingRight) // shotTransform.spriteRenderer.flipY = true; // Assign position shotTransform.position = transform.position; // The is enemy property ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.shooterId = shooterId; } if (!facingRight) { shot.Flip(); } // Make the weapon shot always towards it MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; // towards in 2D space is the right of the sprite } } }
public void AttackBullet(bool isEnemy) { // Create a new shot Transform 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 MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { if (shot.isEnemyShot) { move.direction = -this.transform.right; // towards in 2D space is the right of the sprite } else { move.direction = this.transform.right; EnergyScript energy = GetComponentInParent <EnergyScript>(); energy.Decrement(1); } } }
void OnTriggerEnter2D(Collider2D otherCollider) { // does the otherCollider have a shot script? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { // destroy the shot Destroy(shot.gameObject); // split sub-asteroids if (splitThis) { for (int i = 1; i <= splitCopies; i++) { asteroidTransform = Instantiate(asteroidPrefab, myTrans.position, Quaternion.identity) as Transform; } } // increment score UIScript uiScript = GameObject.Find("UICanvas").GetComponent <UIScript>(); if (uiScript != null) { uiScript.ScoreAdd(score); } // destroy this asteroid Destroy(gameObject); } }
//-------------------------------- // 3 - Shooting з іншого сценарію //-------------------------------- /// <summary> /// Створіть новий снаряд, якщо це можливо /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Створіть новий снаряд var shotTransform = Instantiate(shotPrefab) as Transform; // Призначити позицію shotTransform.position = transform.position; // це постріл ворога ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // Зробіть, щоб зброя завжди вбивала його MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; // в напрямку 2D-простору - право sprite } } }
public void Attack(bool isEnemy) { if (CanAttack) { shootCoolDown = shootingRate; // создание нового выстрела var shotTransform = Instantiate(shotPrefab) as Transform; //определение положения shotTransform.position = transform.position; //свойство врага ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // направляем выстрел на врага MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; } } }
void OnTriggerEnter2D(CircleCollider2D otherCollider) { // Is this a shot? bombchase shot = otherCollider.gameObject.GetComponent <bombchase>(); if (shot != null) { // Avoid friendly fire if (shot.isEnemyBomb != isEnemy) { } } ShotScript blast = otherCollider.gameObject.GetComponent <ShotScript>(); if (blast != null) { // Avoid friendly fire if (blast.isEnemyShot != isEnemy) { PlayBurst(); Damage(blast.damage); // Destroy the shot Destroy(blast.gameObject); } } }
void Fire(float axis) { smoke.Smoke(); shootCooldown = shootingRate; var shotobject = Instantiate(projectile) as GameObject; // Assign position shotobject.transform.position = transform.position; ShotScript shot = shotobject.GetComponent <ShotScript>(); if (shot != null) { shot.SetPlayerShoot(this.id); } // Make the weapon shot always towards it MoveScript move = shotobject.GetComponent <MoveScript>(); if (move != null) { move.direction = (facingRight)? this.transform.right : -this.transform.right; // towards in 2D space is the right of the sprite } move.impulsionDirection(axis); }
public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRange; var shotTransform = Instantiate(shotPrefab) as Transform; if (right) { shotTransform.position = new Vector3(transform.position.x + .15f, transform.position.y + .03f, 0f); } else { shotTransform.position = new Vector3(transform.position.x - .15f, transform.position.y + .03f, 0f); } ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { if (right) { move.direction = this.transform.right; } else { move.direction = this.transform.right * -1; } } } }
public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; var shotTransform = Instantiate(shotPrefab) as Transform; shotTransform.position = transform.position; ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { if (toTheRight) { move.direction = this.transform.right; } else { move.direction = -this.transform.right; } } } }
private void OnTriggerEnter2D(Collider2D collision) { ShotScript shot = collision.gameObject.GetComponent <ShotScript>(); if (shot != null) { if (shot.isEnemyShot != isEnemy) { if (GetComponent <PlayerScript>() != null) { // If the player gets attacked, the UI hearts will disappear // one by one. for (int i = 0; i < shot.damage; i++) { Damage(1); Destroy(GetComponent <PlayerScript>().hearts[hp]); } } else { Damage(shot.damage); } Destroy(shot.gameObject); } } }
public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; var shotTransform = Instantiate(shotPrefab) as Transform; shotTransform.position = transform.position + shotOffset; ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } Destroy(shotTransform.gameObject, 2); Vector2 mousePos = Input.mousePosition; Vector2 objPos = Camera.main.WorldToScreenPoint(transform.position); mousePos.x = -(mousePos.x - objPos.x); mousePos.y = -(mousePos.y - objPos.y); float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg; Vector3 rotation = new Vector3(0, 0, angle); //shotTransform.rotation = Quaternion.Euler(rotation); shotTransform.transform.RotateAround(transform.position, new Vector3(0, 0, 1), angle); shotTransform.GetComponent <Rigidbody2D>().AddForce(shotTransform.transform.right.normalized * shotSpeed); } }
void OnTriggerEnter2D(Collider2D otherCollider) { // Is this a shot? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { // Avoid friendly fire if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); // Destroy the shot Destroy(shot.gameObject); } } DamageScript damage1 = otherCollider.gameObject.GetComponent <DamageScript>(); if (damage1 != null) { if (damage1.isEnemyShot != isEnemy) { Damage(damage1.damage); } } }
public void AttackPlayer(bool isEnemy) { //Transform target = GameObject.FindWithTag ("Player").transform; 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 MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = new Vector2((-transform.position.x + Player.transform.position.x) , (-transform.position.y + Player.transform.position.y)).normalized; } } }
void OnTriggerEnter2D(Collider2D otherCollider) { // Is this a shot? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { // Avoid friendly fire if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); // Destroy the shot Destroy(shot.gameObject); // Remember to always target the game object, otherwise you will just remove the script } } ShotsScript shots = otherCollider.gameObject.GetComponent <ShotsScript>(); if (shots != null) { // Avoid friendly fire if (shots.isEnemyShot != isEnemy) { Damage(shots.damage); // Destroy the shot Destroy(shots.gameObject); // Remember to always target the game object, otherwise you will just remove the script } } }
public void AttackAngled(bool isEnemy, Vector2 direction) { if (direction == new Vector2(0, 0)) { direction = new Vector2(0, 1); } if (CanAttack) { shootCooldown = shootingRate; // Create a new shot var shotTransform = Instantiate(shotPrefab) as Transform; shotTransform.SetParent(gameObject.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 MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { //new Vector2((transform.position.x - player.position.x) * speed, (transform.position.y - player.position.y) * speed); move.direction = direction; } } }
// Shooting from another script // Create new shoot public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Create new shot var shotTransform = Instantiate(shotPrefab) as Transform; // Define position shotTransform.position = transform.position; // Enemy properties ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // Direction to enemy MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; } } }
public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; var shotTransform = Instantiate(shotPrefab) as Transform; shotTransform.position = transform.position; ShotScript shot = shotTransform.gameObject.GetComponent <ShotScript>(); if (shot != null) { shot.isEnemyShot = isEnemy; } MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { // move.direction = player.transform.position.normalized; move.direction = new Vector2(-(this.transform.position.x - player.transform.position.x), -(this.transform.position.y - player.transform.position.y)).normalized; } } }
//-------------------------------- // 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 MoveShotScript move = shotTransform.gameObject.GetComponent <MoveShotScript>(); if (move != null) { move.direction = this.transform.right; // towards in 2D space is the right of the sprite } } }
/// <summary> /// Flash enemes when hit. /// </summary> IEnumerator Flash( ShotScript shotFrom) { // if (!shotFrom.isEnemyShot) { gameObject.renderer.material.color = new Color (200f, 0f, 0f, 1f); yield return new WaitForSeconds (0.08f); gameObject.renderer.material.color = new Color (1f, 1f, 1f, 1f); //} // else { // gameObject.renderer.material.color = new Color (248f, 248f, 255f, 1f); // yield return new WaitForSeconds (0.08f); // gameObject.renderer.material.color = new Color (1f, 1f, 1f, 1f); // } }
// Use this for initialization void Start() { //find your daddy parentShot = this.transform.parent.GetComponent<ShotScript> ();; }