override public void beAttackByBullet(GameObject obj) { //Debug.Log ("玩家被子弹攻击"); if (isWUDI()) { return; } bullet_property bulletProperty = obj.GetComponent <bullet_property>(); if (bulletProperty != null) { char_property charProperty = gameObject.GetComponent <char_property>(); charProperty.Hp = charProperty.Hp - bulletProperty.bulletDamage; if (bulletProperty.bulletknock != 0) { //Debug.Log (gameObject.name + "被击退.武器类型为:"); getKnockBack(charProperty, bulletProperty); } if (isDie()) { constant.getGameLogic().Die(); } if (bulletProperty.bulletDamage > 0) { setWUDI(); } } }
//被 -攻击- 逻辑处理 override public void beAttack(GameObject obj) { if (obj.tag.Equals("Bullet")) { bullet_property bulletProperty = obj.GetComponent <bullet_property>(); enemy_property enemyProperty = gameObject.GetComponent <enemy_property>(); if (enemyProperty.invincible == false) { getDamage(enemyProperty, bulletProperty); } //判断击退类型 if (bulletProperty.bulletknock != 0) { //Debug.Log (gameObject.name + "被击退.武器类型为:"); getKnockBack(enemyProperty.gameObject, bulletProperty); } //判断攻击特效附加效果 checkBulletEffect(gameObject, obj); if (isDie()) { GameObject.Destroy(this.gameObject); constant.getMapLogic().checkOpenDoor(); } } }
void OnTriggerStay(Collider other) { //判断是的是否开始工作 if (doDamage) { bulletPro = gameObject.GetComponent <bullet_property>(); //主角发出的子弹 if (bulletPro.BattleType == constant.BattleType.Player) { enemylogic logic = other.gameObject.GetComponent <enemylogic> (); if (logic) { if (!enemyDictionary.ContainsKey(other.name)) { enemyDictionary.Add(other.name, 99); } if (enemyDictionary[other.name] >= bulletPro.bulletDamageRate) { constant.getMapLogic().triggerEnter(other.gameObject, this.gameObject); //gameObject.GetComponent<bulletAniManager> ().buuletHit = true; //vibrate.joystickVibrate(0.2f,1,1); enemyDictionary[other.name] = 0; } else { //Debug.Log ("伤害间隔中,无法造成伤害 debug_cTime = " + cTime); } } } //敌人发出的子弹 if (bulletPro.BattleType == constant.BattleType.Enemy) { char_property logic = other.gameObject.GetComponent <char_property> (); if (logic) { if (cTime >= bulletPro.bulletDamageRate) { constant.getMapLogic().triggerEnter(other.gameObject, this.gameObject); //gameObject.GetComponent<bulletAniManager> ().buuletHit = true; //vibrate.joystickVibrate(0.2f,1,1); cTime = 0; } else { //Debug.Log ("伤害间隔中,无法造成伤害 debug_cTime = " + cTime); } } } } }
//爆炸击退效果 override public void explodeKnockBack(bullet_property bulletProperty, int force) { //敌人位置 Vector3 enemyPos = this.transform.position; //子弹位置 Vector3 bulletPos = bulletProperty.transform.position; Vector3 bulletSpeed = bulletProperty.transform.rigidbody.velocity; if (bulletSpeed.x != 0 || bulletSpeed.y != 0) { this.gameObject.rigidbody.AddForce(new Vector3(enemyPos.x - bulletPos.x, enemyPos.y - bulletPos.y, 0) * force); } }
//检查子弹的特殊效果 override public void checkBulletEffect(GameObject enemy, GameObject bullet) { bullet_property bulletProperty = bullet.GetComponent <bullet_property> (); enemy_property enemyProperty = enemy.GetComponent <enemy_property> (); if (bulletProperty) { //是否具有恐惧效果 if (bulletProperty.bulletSpe.scaredBullet.scaredEffect) { ScaredBullet scaredBullet = bulletProperty.bulletSpe.scaredBullet; getScared(enemyProperty, scaredBullet); } } }
void Awake() { if (bulletDie == false) { bulletSprite = transform.FindChild("ui").FindChild("bulletPic").GetComponent <tk2dSprite> (); bulletAni = transform.FindChild("ui").FindChild("bulletPic").GetComponent <tk2dSpriteAnimator> (); bulletProperty = gameObject.GetComponent <bullet_property> (); if (getShadow) { shadowSprite = intiShadow(); } } else { GameObject.Destroy(this.gameObject); } }
//普通击退效果 void normalKnockBack(bullet_property bulletProperty, int force) { Direction bulletDirection; bulletDirection = Direction.none; if (bulletProperty.WeaponType == weaponType.laserNormal) { bulletDirection = bulletProperty.gameObject.GetComponent <laserAniManager> ().BulletDirection; } if (bulletProperty.WeaponType == weaponType.bulletNormal) { bulletDirection = bulletProperty.gameObject.GetComponent <bulletAniManager> ().BulletDirection; } if (bulletDirection == Direction.none) { Debug.Log("击退时:获取武器类型出错"); return; } switch (bulletDirection) { default: break; case Direction.up: this.gameObject.rigidbody.AddForce(Vector3.up * force); break; case Direction.down: this.gameObject.rigidbody.AddForce(-1 * Vector3.up * force); break; case Direction.left: this.gameObject.rigidbody.AddForce(-1 * Vector3.right * force); break; case Direction.right: this.gameObject.rigidbody.AddForce(Vector3.right * force); break; break; } }
bool checkBulletPierce() { GameObject bullet = this.gameObject; bullet_property bulletPro = bullet.GetComponent <bullet_property> (); bool canPierce; if (bulletPro) { //Debug.Log("bulletPro.bulletSpe.pierceBullet " + bulletPro.bulletSpe.pierceBullet); canPierce = bulletPro.bulletSpe.pierceBullet; } else { return(true); } //如果子弹有穿透属性,则返回false 不做动画处理 return(!canPierce); }
override public void getKnockBack(GameObject enemy, bullet_property bulletProperty) { enemy_property enemyProperty = enemy.GetComponent <enemy_property> (); //子弹的类型 //weaponType weapontype = bulletProperty.WeaponType; //Debug.Log("bulletProperty.weaponType: " +weapontype); //击退的力度 int force = bulletProperty.bulletknock; //敌人是否有霸体 if (enemyProperty.heavyBody) { return; } //击退的类型 //击退效果分类 //1:普通击退 //2:爆炸击退 //3: KnockType knockType = bulletProperty.bulletSpe.knockType; switch (knockType) { default: break; case KnockType.none: break; case KnockType.normal: normalKnockBack(bulletProperty, force); break; case KnockType.explode: explodeKnockBack(bulletProperty, force); break; break; } }
//获得伤害 public void getDamage(enemy_property enemyProperty, bullet_property bulletProperty) { //Debug.Log("enemy get damage: " + bulletProperty.bulletDamage); enemyProperty.Hp = enemyProperty.Hp - bulletProperty.bulletDamage; Vector3 objectPos = this.transform.position; //伤害显示------------- //调整伤害输出的位置 objectPos.y += 1; objectPos.z = -5; string showDamagePath = "Prefabs/ui/UI_showDamage"; GameObject showDamageClone = (GameObject)Instantiate(Resources.Load(showDamagePath), objectPos, Quaternion.identity); if (showDamageClone) { string damage = "-" + bulletProperty.bulletDamage.ToString(); showDamageClone.GetComponent <enemy_showDamage>().showDamage(damage); } //伤害显示------------ }
public void getKnockBack(char_property player, bullet_property bullet) { }
virtual public void explodeKnockBack(bullet_property bullet, int force) { Debug.Log("敌人击退override函数没写,请注意"); }
virtual public void getKnockBack(GameObject obj, bullet_property bullet) { Debug.Log("敌人击退override函数没写,请注意"); }