private IEnumerator State_AttackingEnemy() { _Agent.isStopped = true; _Agent.ResetPath(); float shootTimer = 0f; while (_TargetEnemy != null && _TargetEnemy.GetIsAlive()) { shootTimer += Time.deltaTime; transform.LookAt(_TargetEnemy.transform); transform.eulerAngles = new Vector3(0f, transform.eulerAngles.y, 0f); if (shootTimer >= _AttackCD) { shootTimer = 0; ShootLasersFromEyes(_TargetEnemy.transform.position + Vector3.up, _TargetEnemy.transform); } // Checks if the Health of the AI is lower than 33% CheckingIfHealthIsLow(); yield return(null); } _TargetEnemy = null; SetState(State_Idle()); }
public void SpawnUnit(AUnit a_Unit, Vector2 a_Pos) { Debug.Assert(Contains(a_Pos)); a_Unit.transform.position = new Vector3(a_Pos.x, a_Pos.y, -1); a_Unit.transform.parent = m_UnitsObj.transform; Units.Add(a_Unit); }
private void OnTriggerStay(Collider other) { AUnit u = other.GetComponent <AUnit>(); if (u == null) { return; } if (u.TeamNumber == CurrentTeam) { CaptureValue += Time.fixedDeltaTime / _CaptureTime; if (CaptureValue > 1f) { CaptureValue = 1f; } } else { CaptureValue -= Time.fixedDeltaTime / _CaptureTime; if (CaptureValue <= 0f) { CaptureValue = 0f; CurrentTeam = u.TeamNumber; } } }
//Damages if a bullet hits a player private void OnCollisionEnter(Collision other) { AUnit aunit = other.gameObject.GetComponent <AUnit>(); if (aunit != null) { // If the collider is a Unit, take damage aunit.OnHit(_Damage); } }
public override IEnumerator KnockCo(AUnit target, float knockTime) { var obj = target.GetComponent <Player>(); var hit = obj.GetComponent <Rigidbody2D>(); if (hit != null) { yield return(new WaitForSeconds(Mathf.Max(_knockTime, knockTime))); hit.velocity = Vector2.zero; obj.currentState = PlayerState.idle; hit.velocity = Vector2.zero; } }
protected void ShootLasersFromEyes(Vector3 hitPos, Transform other) { foreach (var eye in _Eyes) { Instantiate(_LaserPrefab).Shoot(eye.transform.position, hitPos); } AUnit otherUnit = other.GetComponent <AUnit>(); if (otherUnit != null && otherUnit.TeamNumber != TeamNumber) { otherUnit.OnHit(_AttackDamage); } }
private void LookForEnemy() { var aroundMe = Physics.OverlapSphere(transform.position, _AttackRadius, _UnitsLayerMask); foreach (var item in aroundMe) { var otherUnit = item.GetComponent <AUnit>(); if (otherUnit != null && otherUnit.TeamNumber != TeamNumber && otherUnit.GetIsAlive()) { _TargetEnemy = otherUnit; SetState(State_AttackingEnemy()); return; } } }
private void OnTriggerStay(Collider other) { // Increasing the seconds to the heal post stay only heal every second, and not every frame _CountSeconds += Time.deltaTime; if (_CountSeconds >= 1f) { AUnit aunit = other.gameObject.GetComponent <AUnit>(); if (aunit != null) { aunit.Heal(_HealingPoints); } _CountSeconds = 0f; } }
// if the health of the AI is lower than 33%, the AI will shoot the crazy bomb private void CheckingIfHealthIsLow() { if (GetHealth() < GetMaxHealth() / 3) { // Shoot CrazyBomb and Look for the Healing Post ShootCrazyBomb(); LookForHealPost(); if (_TargetHealpost != null) { _TargetEnemy = null; _TargetOutpost = null; // Set the State to Moving To Heal SetState(State_MovingToHeal()); } } }
private void moveAction() { if (Input.GetMouseButtonDown(0) && selectedObject) { RaycastHit hit; Ray ray = new Ray(transform.position, transform.forward); if (Physics.Raycast(ray, out hit, 100) && hit.transform.tag == "map") { AUnit obj = selectedObject.GetComponent <AUnit>(); obj.playMoveSound(); obj.rotateToDirection(hit.point); obj.moveToDestination(hit.point); obj.triggerWalkAnimation(); } } }
/// <summary> /// 按配置放置族 /// </summary> /// <param name="ent"></param> public void SetConfig(SetConfigEnt ent) { if (_selFamily == null) { return; } try { Family family = FindAndLoadFamily(_doc, _selFamily); //创建族实例 FamilySymbol fSymbol = null; ISet <ElementId> idSet = family.GetFamilySymbolIds(); if (idSet.Count > 0) { fSymbol = _doc.GetElement(idSet.ElementAt <ElementId>(0)) as FamilySymbol; if (!fSymbol.IsActive) { fSymbol.Activate(); } //获取实例参数 FamilyInstance instance = _doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); string len = instance.LookupParameter("长度").AsValueString(); string wid = instance.LookupParameter("宽度").AsValueString(); string hei = instance.LookupParameter("高度").AsValueString(); double length = double.Parse(len); double width = double.Parse(wid); double height = double.Parse(hei); _doc.Delete(instance.Id); RoomTag rmtag = FindRoomTag(_doc, ent.RoomName); Room room = rmtag.Room; BoundingBoxXYZ boundingBoxXYZ = room.get_BoundingBox(_doc.ActiveView); XYZ minPoint = boundingBoxXYZ.Min; XYZ maxPoint = boundingBoxXYZ.Max; XYZ minp = AUnit.FT2MM(minPoint); XYZ maxp = AUnit.FT2MM(maxPoint); var roomLength = maxp.X - minp.X; //房间长度 var roomWidth = maxp.Y - minp.Y; //房间宽度 double lenCount = Math.Floor(roomLength / length); double widCount = Math.Floor(roomWidth / width); if (ent.Num > lenCount * widCount) { TaskDialog.Show("提示", "当前房间仅能摆放此族" + lenCount * widCount + "个"); return; } if (ent.Direction == "横向") { double allCount = Math.Ceiling(ent.Num / lenCount); for (int i = 1; i <= allCount; i++) { double y = 0; if (i == 1) { y = width / 2; } else { y = width * i - width / 2; } for (int j = 1; j <= lenCount; j++) { if (i * j > ent.Num) { break; } double x = 0; if (j == 1) { x = length / 2; } else { x = length * j - length / 2; } XYZ point = minp + new XYZ(x, y, 0); point = AUnit.MM2FT(point); //创建族实例 FamilyInstance fi = _doc.Create.NewFamilyInstance(point, fSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } } else if (ent.Direction == "纵向") { double allCount = Math.Ceiling(ent.Num / widCount); for (int i = 1; i <= allCount; i++) { double x = 0; if (i == 1) { x = length / 2; } else { x = length * i - length / 2; } for (int j = 1; j <= widCount; j++) { if (i * j > ent.Num) { break; } double y = 0; if (j == 1) { y = width / 2; } else { y = width * j - width / 2; } XYZ point = minp + new XYZ(x, y, 0); point = AUnit.MM2FT(point); //创建族实例 FamilyInstance fi = _doc.Create.NewFamilyInstance(point, fSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } } } } catch (Exception ex) { TaskDialog.Show("错误", ex.Message); return; } TaskDialog.Show("提示", "创建成功"); }
public abstract IEnumerator KnockCo(AUnit target, float knockTime);