public void GetBeHit(JN_Date jn_date, float sx) { //print("被击中 !! "+this.transform.name+" 攻击力 "+ jn_date.atkPower+" 我的防御力 "+this.GetComponent<RoleDate>().def); gameBody = GetComponent <GameBody>(); roleDate = GetComponent <RoleDate>(); if (roleDate.isDie) { return; } float addxue = jn_date.atkPower - this.GetComponent <RoleDate>().def; addxue = addxue > 0 ? addxue : 1; roleDate.live -= addxue; if (roleDate.live < 0) { roleDate.live = 0; } //print("live "+ roleDate.live); if (!roleDate.isCanBeHit) { return; } if (gameBody != null) { //判断是否破防 D 代办事项 if (jn_date.atkPower - roleDate.yingzhi > 0) { } gameBody.HasBeHit(); } //判断是否在躲避阶段 无法被攻击 //判断击中特效播放位置 //击退 判断方向 float _psScaleX = sx; //判断是否在空中 //挨打动作 判断是否破硬直 //判断是否生命被打空 Bloods(_psScaleX); }
void OnTriggerEnter2D(Collider2D Coll) { gameBody = Coll.GetComponent <GameBody>(); roleDate = Coll.GetComponent <RoleDate>(); _rigidbody2D = Coll.GetComponent <Rigidbody2D>(); var txObj = this.transform.parent; atkObj = txObj.GetComponent <JN_base>().atkObj; JN_Date jn_date = txObj.GetComponent <JN_Date>(); if (roleDate != null && roleDate.team != jn_date.team) { //print("击中的2Dbox "+Coll.GetComponent<BoxCollider2D>().transform.position); if (roleDate.isDie) { return; } if (!roleDate.isCanBeHit) { return; } //取到施展攻击角色的方向 float _roleScaleX = -atkObj.transform.localScale.x; //这个已经不需要了 //if (Coll.GetComponent<BeHit>()) Coll.GetComponent<BeHit>().GetBeHit(jn_date, _roleScaleX); GetBeHit(jn_date, _roleScaleX); //力作用 这个可以防止 推力重叠 导致任务飞出去 Vector3 tempV3 = _rigidbody2D.velocity; _rigidbody2D.velocity = new Vector3(0, tempV3.y, tempV3.z); if (jn_date != null && gameBody != null) { //判断是否破防 D 代办事项 if (jn_date.atkPower - roleDate.yingzhi > roleDate.yingzhi * 0.5) { gameBody.HasBeHit(); //Coll.GetComponent<Rigidbody2D>().AddForce(new Vector2(400 * _roleScaleX, 0)); gameBody.GetZongTuili(new Vector2(400 * _roleScaleX, 0)); } else if (jn_date.atkPower - roleDate.yingzhi > 0) { gameBody.HasBeHit(); //Coll.GetComponent<Rigidbody2D>().AddForce(new Vector2(300 * _roleScaleX, 0)); gameBody.GetZongTuili(new Vector2(300 * _roleScaleX, 0)); if (atkObj && jn_date._type == "1") { atkObjV3Zero(); //atkObj.GetComponent<Rigidbody2D>().AddForce(new Vector2(-300 * _roleScaleX, 0)); atkObj.GetComponent <GameBody>().GetZongTuili(new Vector2(-300 * _roleScaleX, 0)); } } else { if (atkObj && jn_date._type == "1") { atkObjV3Zero(); //atkObj.GetComponent<Rigidbody2D>().AddForce(new Vector2(-500 * _roleScaleX, 0)); atkObj.GetComponent <GameBody>().GetZongTuili(new Vector2(-500 * _roleScaleX, 0)); } } } //判断作用力与反作用力 硬直判断 // //Coll.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 300)); //如果是碰撞就消失 调用消失方法 if (jn_date != null && jn_date._type == "3") { //if (gameObject) ObjectPools.GetInstance().DestoryObject2(gameObject); txObj.GetComponent <JN_base>().DisObj(); } } }
void OnTriggerEnter2D(Collider2D Coll) { gameBody = Coll.GetComponent <GameBody>(); roleDate = Coll.GetComponent <RoleDate>(); _rigidbody2D = Coll.GetComponent <Rigidbody2D>(); //atkObj = txObj.GetComponent<JN_base>().atkObj; //print(atkObj.name); print(" ---coll name " + Coll.name + " roledate " + roleDate); if (roleDate && !IsCanHitBoss && roleDate.enemyType == "boss") { return; } JN_Date jn_date = GetComponent <JN_Date>(); if (roleDate != null && roleDate.team != jn_date.team) { //print("击中的2Dbox "+Coll.GetComponent<BoxCollider2D>().transform.position); if (roleDate.isDie) { return; } //if (!roleDate.isCanBeHit) return; //取到施展攻击角色的方向 //float _roleScaleX = -atkObj.transform.localScale.x; if (IsCanBeDodge) { //print("roleDate " + roleDate); //print(" isCanbeihit " + roleDate.isCanBeHit); if (!roleDate.isCanBeHit) { return; } } //这个已经不需要了 //if (Coll.GetComponent<BeHit>()) Coll.GetComponent<BeHit>().GetBeHit(jn_date, _roleScaleX); //print(" 这里是否进来 " + Coll.transform.position.x + " ------- " + this.transform.parent.transform.transform); if (this.transform.parent) { atkScaleX = Coll.transform.position.x < this.transform.parent.transform.position.x ? -1 : 1; } GetBeHit(jn_date, atkScaleX); //力作用 这个可以防止 推力重叠 导致任务飞出去 Vector3 tempV3 = _rigidbody2D.velocity; _rigidbody2D.velocity = new Vector3(0, tempV3.y, tempV3.z); if (jn_date != null && gameBody != null) { gameBody.HasBeHit(); if (this.transform.parent == null) { return; } if (Coll.transform.position.x > this.transform.parent.transform.position.x) { //Coll.GetComponent<Rigidbody2D>().AddForce(new Vector2(400 , 0)); Coll.GetComponent <GameBody>().GetZongTuili(new Vector2(400, 0)); } else { //Coll.GetComponent<Rigidbody2D>().AddForce(new Vector2(-400 , 0)); Coll.GetComponent <GameBody>().GetZongTuili(new Vector2(-400, 0)); } } //毒伤害 if (jn_date.DuChixuShanghai != 0) { //print(beHitObj.name + " --beihitteam " + BeHitRoleDate.team + " jnteam " + jn_date.team + " atkObjname " + atkObj.name); if (gameBody != null && roleDate.team != jn_date.team) { gameBody.GetComponent <ChiXuShangHai>().InDu(jn_date.DuChixuShanghai, jn_date.DuChixuShanghaiTime); } } if (jn_date.HuoChixuShanghai != 0) { if (gameBody != null && roleDate.team != jn_date.team) { gameBody.GetComponent <ChiXuShangHai>().InHuo(jn_date.HuoChixuShanghai, jn_date.HuoChixuShanghaiTime); } } } }