public void activate(GameObject player) { var pl = player.GetComponent <Player>(); float divider = pl == null ? 1 : pl.weaponSpeedMultiplier; if (Time.time - this.previousActivation > this.firedelay / divider) { //Allow fire for (int i = 0; i < bulletAmount; i++) { //Spawn a bullet var go = player.tag == "Enemy"? bulletPoolEnemy[this.bulletEnemyPrefab.name][(bulletIndicesEnemy[bulletEnemyPrefab.name]++) % bulletPoolSize] : bulletPool[this.bulletPrefab.name][(bulletIndices[bulletPrefab.name]++) % bulletPoolSize]; go.transform.parent = bulletContainer.transform; go.transform.rotation = player.transform.rotation; go.transform.position = player.transform.Find("shootPoint").position; /*GameObject.Instantiate(bulletPrefab, player.transform.Find("shootPoint").position, * player.transform.rotation * , this.bulletContainer.transform);*/ go.SetActive(true); float angle = this.transform.rotation.eulerAngles.y + (UnityEngine.Random.value - 0.5f) * (spread); Vector3 add = new Vector3( Mathf.Sin(angle * Mathf.PI / 180f), Mathf.Sin(heightAngle * 180f / Mathf.PI), Mathf.Cos(angle * Mathf.PI / 180f) ); add.Normalize(); float addSpeed = 1f; float addDamage = 1f; //TODO - this might be moved to interface at some point, but for now. Lets keep it at player. if (pl != null) { // addSpeed = pl.weaponSpeedMultiplier; addDamage = pl.weaponDamageMultiplier; } else { //Enemies shoot halved speed.s addSpeed = 0.1f * GameConfig.difficulty + 0.7f; addDamage *= GameConfig.difficulty; } // Debug.Log("Shoot angle: " + add); go.GetComponent <IAmmunition>().shooter = player; go.GetComponent <IAmmunition>().direction = add * (bulletspeed * addSpeed + UnityEngine.Random.value * bulletSpeedRandomFactor * addSpeed) + 0f * player.GetComponent <ITarget>().m_Move; // Debug.Log("final shoot: " + go.GetComponent<IAmmunition>().direction); go.GetComponent <IAmmunition>().damage = this.bulletDamage * addDamage; go.GetComponent <IAmmunition>().effectRadius = this.effectRadius; go.GetComponent <IAmmunition>().bulletToShotRatio = 1f / (float)this.bulletAmount; } StatisticManager.calculateShotStatistics(pl, bulletAmount); this.previousActivation = Time.time; } }