//攻击敌人 public void AttackEnemy(ActionSoliderAttack bNodeAction) { //.1创建子弹 GameObject bulletObject = Instantiate(Resources.Load("Prefab/Bullet")) as GameObject; bulletObject.transform.SetParent(this.transform); bulletObject.transform.localPosition = new Vector3(0, 0, 0); bulletList.Add(bulletObject); Transform safeSpacObj = this.transform.Find("SafeSpace"); List <EnemySoliderPlayer> inSightEnemyList = safeSpacObj.GetComponent <SafeSpaceScript> ().inSightEnemyList; //2.找到一个在视野内的敌人 foreach (EnemySoliderPlayer enemyPlayer in inSightEnemyList) { bulletObject.GetComponent <BulletScript> ().RuningBullet(this.transform, enemyPlayer.transform); break; } }
//攻击敌人 public void AttackEnemy(ActionSoliderAttack bNodeAction) { animator.Play("Shoot"); shootTimer -= Time.deltaTime; if (shootTimer <= 0) { //SetAmmo(1); shootTimer = 0.9f; // 用一个RaycastHit对象保存射线的碰撞结果 RaycastHit info; // 从枪口所在位置向摄像机面向的正前方发出一条射线 // 该射线只与layer指定的层发生碰撞 if (Physics.Raycast(muzzlePoint.position, transform.TransformDirection(Vector3.forward), out info, 100, layer)) { // 判断是否射中Tag为enemy的物体 if (info.transform.tag.Equals("enemy")) { // 敌人减少生命 info.transform.GetComponent <Enemy>().OnDamage(1); } } // 在射中的地方释放一个粒子效果 Debug.Log(fx + " " + info.point + " " + info.transform.rotation); Instantiate(fx, info.point, info.transform.rotation); } //.1创建子弹 /*GameObject bulletObject = Instantiate(Resources.Load ("Prefab/Bullet")) as GameObject; * bulletObject.transform.SetParent ( this.transform ); * bulletObject.transform.localPosition = new Vector3 (0,0,0); * bulletList.Add (bulletObject); * * Transform safeSpacObj = this.transform.Find ("SafeSpace"); * List<EnemySoliderPlayer> inSightEnemyList = safeSpacObj.GetComponent<SafeSpaceScript> ().inSightEnemyList; * * //2.找到一个在视野内的敌人 * foreach(EnemySoliderPlayer enemyPlayer in inSightEnemyList){ * bulletObject.GetComponent<BulletScript> ().RuningBullet ( this.transform,enemyPlayer.transform ); * break; * } */ }