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 startRunToTarget() { //被攻击 中断 if (GetComponent <RoleDate>().isDie || GetComponent <RoleDate>().isBeHiting) { ReSetAll(); return; } //判断 前面如果撞墙 就结束 if (_gameBody.IsHitWall) { print("------------------------------------------- 冲刺撞墙 "); ReSetAll(); return; } if (IsHasQSAC && !_isQiShiAcOver) { //print("进来没????? " + QishiACName+" shifouhanyouAC "+); //起始动作做完 if (_gameBody.GetDB().animation.lastAnimationName != QishiACName) { //_player.GetComponent<GameBody>().GetDB().animation.GotoAndPlayByFrame(QishiACName); //print("?????????????进来没??"); _gameBody.GetAcMsg(QishiACName); } else { //print("------->> 1"); if (_gameBody.GetDB().animation.isCompleted) { _isQiShiAcOver = true; } } return; } //下压的力 放置 角色飞起来了 //_gameBody.GetPlayerRigidbody2D().AddForce(new Vector2(0, -20)); _gameBody.GetZongTuili(new Vector2(0, -20)); if (runDirection == "right") { _gameBody.RunRight(3f); } else { _gameBody.RunLeft(-3f); } if (Mathf.Abs(this.transform.position.x - _positionX) >= Distances) { ReSetAll(); } if (!IsShowTXAndHitKuai && _isStarting) { //print(" 速度是多少: "+_gameBody.GetPlayerRigidbody2D().velocity.x); if (Mathf.Abs(_gameBody.GetPlayerRigidbody2D().velocity.x) < 3) { return; } IsShowTXAndHitKuai = true; //print("_gameBody.GetDB().animation.lastAnimationName " + _gameBody.GetDB().animation.lastAnimationName); HitKuai.SetActive(true); //HitKuai.transform.position = this.transform.position; ShowTX(); } if (HitKuai) { //hitkuai跟随 特效的位置 后面也可以加一个参照点 跟随参照点 HitKuai.transform.position = Lizi.transform.position; } }
// Update is called once per frame void Update() { if (_roleDate.isBeHiting || _roleDate.isDie) { _gameBody.GetZongTuili(new Vector2(0, 0)); } if (_roleDate.isBeHiting || _roleDate.isDie || (_gameBody.IsGround && _gameBody.IsGetStand())) { //_gameBody.GetPlayerRigidbody2D().gravityScale = _recordGravity; _gameBody.isJumping = false; //print(" ******* 技能终止!!!!! "); ReSetAll(); IsStarting = false; } if (!IsStarting) { return; } if (GetComponent <AIBase>().IsTuihuiFangshouquing) { ReSetAll(); return; } //撞墙判断 if (_gameBody.IsShentiHitWall && !_roleDate.isDie) { //float vx = this.transform.localScale.x > 0 ? 0.2f : -0.2f; float vx = this.transform.localScale.x > 0 ? 400 : -400; print(" 身体 前面撞墙了!!!!! " + vx); _gameBody.GetZongTuili(new Vector2(vx, 0)); //GetZongTuili(Vector2.up * yForce); //_gameBody.GetPlayerRigidbody2D().velocity = new Vector2(vx, _gameBody.GetPlayerRigidbody2D().velocity.y); //print(_gameBody.GetPlayerRigidbody2D().velocity); //float __x = this.transform.position.x + vx; //print(vx+" --- "+this.transform.position); //this.transform.position = new Vector2(__x, this.transform.position.y); //print(this.transform.position); //IsKaqiang = true; return; } //if(_gameBody.GetDB().animation.lastAnimationName == "jumpUp_1"&& _gameBody.GetPlayerRigidbody2D().velocity == Vector2.zero) //{ // if (IsKaqiang) // { // IsKaqiang = false; // print("我靠 发什么神经!!!!!" + _gameBody.GetPlayerRigidbody2D().gravityScale); // float vx = this.transform.localScale.x > 0 ? 100 : -100; // _gameBody.GetZongTuili(new Vector2(vx, 100)); // } //} if (!_roleDate.isDie && IsJumpToPlayerPostion && IsStartXV && _gameBody.isInAiring && _gameObj) { //print("我进来没、、、、、、、、、、、、、、///////////////////////////////////-------------->"); StartVX(); } }