public void shootBullet(EnemyShotType shotType) { GameObject bulletClone; bulletClone = (GameObject)Instantiate(Resources.Load(bulletPath), this.transform.position, Quaternion.identity); if (shotType == EnemyShotType.directRandom) { } if (shotType == EnemyShotType.directPlayer) { //set bullet end distance bulletClone.GetComponent <bulletCheckDistance> ().setDistance(mbulletDistance); //子弹的damage + 速度 +方向 setBulletProperty(bulletClone); shotScript = bulletClone.GetComponent <bulletGetSpeed> (); setBulletSpeed(shotScript, mbulletSpeed); } if (shotType == EnemyShotType.random) { bulletClone.GetComponent <bulletCheckDistance> ().setDistance(mbulletDistance); //子弹的damage + 速度 +方向 setBulletProperty(bulletClone); shotScript = bulletClone.GetComponent <bulletGetSpeed> (); setRandomSpeed(shotScript, mbulletSpeed); } }
//设置子弹飞行方向 void setDirectionDivergingSpeed(bulletGetSpeed speedScript, float Speed, Vector3 pos, int num, int angle) { Vector3 speedDir = new Vector3(0, 0, 0); Vector3 enemyPos = this.transform.position; speedDir = pos - enemyPos; speedDir.z = 0; //Debug.Log (num + " num : old Vector = " + speedDir); //speedDir.Normalize (); //Quaternion rot = new Quaternion(0,0, Mathf.Sin(num*10/2) , Mathf.Cos(num*10/2) ); speedScript.gameObject.transform.position += speedDir.normalized; Quaternion rot; if (num % 2 == 1) { num -= 1; rot = Quaternion.Euler(0f, 0f, -1 * (num / 2) * angle); } else { rot = Quaternion.Euler(0f, 0f, (num / 2) * angle); } speedDir = rot * speedDir; //Debug.Log (num + " num : new Vector = " + speedDir); //speedDir.Normalize (); //speedDir.x += (num-1)*4; speedScript.shotBullet(speedDir.normalized * Speed); }
void setBulletSpeed(bulletGetSpeed anyScript, float Speed) { Vector3 speed = new Vector3(0, 0, 0); if (player.rigidbody) { playerVelocity = player.rigidbody.velocity; } else { playerVelocity = new Vector3(0, 0, 0); } //Debug.Log("人物移动速度: " +playerVelocity ); getBulletDirection(); switch (bulletDirection) { default: break; case Direction.up: speed = new Vector3(0, Speed, 0); speed += new Vector3(playerVelocity.x, 0, 0) * velocityTransfer; break; case Direction.down: speed = new Vector3(0, Speed * -1, 0); speed += new Vector3(playerVelocity.x, 0, 0) * velocityTransfer; break; case Direction.left: speed = new Vector3(Speed * -1, 0, 0); speed += new Vector3(0, playerVelocity.y, 0) * velocityTransfer; break; case Direction.right: speed = new Vector3(Speed, 0, 0); speed += new Vector3(0, playerVelocity.y, 0) * velocityTransfer; break; break; } anyScript.shotBullet(speed); }
//设置子弹飞行方向 void setRandomSpeed(bulletGetSpeed speedScript, float Speed) { int randomX = Random.Range(-180, 181); int randomY = Random.Range(-180, 181); Vector3 speedDir = new Vector3(randomX, randomY, 0); speedScript.shotBullet(speedDir.normalized * Speed); }
void shotBullet() { GameObject bulletClone = (GameObject)Instantiate(bulletPrefabs, this.transform.position, Quaternion.identity); bulletSprite = bulletClone.transform.FindChild("bulletPic").GetComponent <tk2dSprite>(); setBulletDireciton(bulletSprite); shotScript = bulletClone.GetComponent <bulletGetSpeed>(); setBulletSpeed(shotScript, bulletSpeed); }
//设置子弹飞行方向 void setBulletSpeed(bulletGetSpeed speedScript, float Speed) { Vector3 speedDir = new Vector3(0, 0, 0); Vector3 enemyPos = this.transform.position; Vector3 playerPos = getPlayerPosExact(); speedDir = playerPos - enemyPos; speedDir.z = 0; speedScript.shotBullet(speedDir.normalized * Speed); }
void shootBullet() { getBulletDirection(); //按键设定子弹的飞行方向 setShotPosition(); //设置子弹的发射位置 GameObject bulletClone = (GameObject)Instantiate(Resources.Load(bulletPath), shotPosition, Quaternion.identity); //set bullet end distance bulletClone.GetComponent <bulletCheckDistance>().setDistance(mbulletDistance); //子弹的damage + 速度 +方向 setBulletProperty(bulletClone); shotScript = bulletClone.GetComponent <bulletGetSpeed>(); setBulletSpeed(shotScript, mbulletSpeed); }
public void shootMultiBullets(EnemyShotType shotType, int bulletAmount, int angle) { //子弹是向着主角方向发散型 if (shotType == EnemyShotType.directDiverging) { Vector3 playerPos = getPlayerPosExact(); for (int i = 1; i <= bulletAmount; i++) { GameObject bulletClone = (GameObject)Instantiate(Resources.Load(bulletPath), this.transform.position, Quaternion.identity); bulletClone.GetComponent <bulletCheckDistance> ().setDistance(mbulletDistance); setBulletProperty(bulletClone); shotScript = bulletClone.GetComponent <bulletGetSpeed> (); setDirectionDivergingSpeed(shotScript, mbulletSpeed, playerPos, i, angle); } } }
void setBulletSpeed(bulletGetSpeed anyScript, float Speed) { Vector3 speed = new Vector3(0, 0, 0); getBulletDirection(); switch (bulletDirection) { default: break; case Direction.up: speed = new Vector3(0, Speed, 0); break; case Direction.down: speed = new Vector3(0, Speed * -1, 0); break; case Direction.left: speed = new Vector3(Speed * -1, 0, 0); break; case Direction.right: speed = new Vector3(Speed, 0, 0); break; break; } anyScript.shotBullet(speed); }