/** 打飞 */ public void HitFly() { if (unitData.unitType == UnitType.Solider) { SteeringAgentComponent m_steeringAgent = GetComponent <SteeringAgentComponent>(); m_steeringAgent.StopSteering(); if (transform.position != unitData.hitFlyPoint) { Vector3 dir = (unitData.hitFlyPoint - transform.position).normalized; unitAgent.angel = HMath.AngleBetweenForward2Vector(dir); } else { unitData.hitFlyPoint += (unitData.to.unit.transform.position - transform.position).normalized * 3f; } Rigidbody rigidbody = GetComponent <Rigidbody>(); rigidbody.useGravity = true; rigidbody.AddExplosionForce(unitData.hitFlyPower, unitData.hitFlyPoint, unitData.hitFlyPowerRadius, unitData.hitFlyPowerUp); unitAgent.action = "die"; // BSolider_Alpha_Hide soliderAlphaHide = GetComponent<BSolider_Alpha_Hide>(); // soliderAlphaHide.enabled = true; // Collider collider = GetComponent<Collider>(); // collider.enabled = true; } }
protected override void OnUpdate() { base.OnUpdate(); if (state == UnitPathState.None) { return; } if (needAround) { if (state == UnitPathState.Moveing) { RelationType relation = unitData.GetRelation(unitData.to.legionId); if (relation == RelationType.Enemy) { path.group.Around(unitData, transform.position); } } else if (state == UnitPathState.Around) { if (Vector3.Distance(transform.position, aroundPoint) < aroundAtkRadius) { state = UnitPathState.AroundAtk; unitAgent.action = "attack"; unitData.to.aroundList.Add(unitData); } } } if (_freezed == false) { if (_distanceFrom <= 5) { _distanceFrom = Vector3.Distance(transform.position, unitData.from.unit.transform.position); } if (_distanceFrom > 5) { unitAgent.angel = HMath.AngleBetweenForward2Vector(rigibody.velocity); } } if (state == UnitPathState.Moveing || state == UnitPathState.Around) { unitAgent.anchorAngle.eulerAngles = new Vector3(0f, unitAgent.angel, 0f); } else if (state == UnitPathState.AroundAtk) { Vector3 pos = transform.position; Vector3 o = unitData.to.unit.transform.position; unitAgent.angel = HMath.angle(pos.z, pos.x, o.z, o.x); } if (state == UnitPathState.Around || state == UnitPathState.AroundAtk) { RelationType relation = unitData.GetRelation(unitData.to.legionId); if (relation != RelationType.Enemy) { In(false); } } if (unitData != null) { if (_moveSpeed != unitData.moveSpeed) { _moveSpeed = unitData.moveSpeed; //TODO 查询路线BUG OnSpeedChange(); } if (_freezed != unitData.freezedMoveSpeed) { _freezed = unitData.freezedMoveSpeed; if (_freezed) { m_steeringAgent.enabled = false; rigibody.velocity = Vector3.zero; } else { m_steeringAgent.enabled = true; } } if (_freezed) { if (unitAgent.action != "die") { unitAgent.speed = 0; } else { unitAgent.speed = 1; } } else { if (unitAgent.action == "walk" && unitData.moveSpeed <= 0) { unitAgent.speed = 0; } else { unitAgent.speed = 1; } } } if (state == UnitPathState.Die) { dieTime += Time.deltaTime; if (transform.position.y < -1 || dieTime > dieTimeMax) { War.hunManager.Play(unitCtl.unitData.colorId, transform.position.SetY(0)); SoliderPoolItem soliderPoolItem = GetComponent <SoliderPoolItem>(); if (soliderPoolItem != null) { soliderPoolItem.Release(); } else { DestroyObject(gameObject); } } } }