//-------------------------------- // 3 - Shooting from another script //-------------------------------- /// <summary> /// Create a new projectile if possible /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { SoundEffectsHelper.Instance.MakeShotSound(); shootCooldown = shootingRate; ammunition -= 1; 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 = transform.right; // towards in 2D space is the right of the sprite } ammoCounter.DecreaseCounter(); } }