public IEnumerator KillCor(Liver2D victim, float time) { LiverInteract = victim; victim.EnemyInteract = this; mover.StopMove(); victim.mover.StopMove(); isBusy = true; victim.isBusy = true; // направление mover.RotateTo(victim.transform.position); yield return(new WaitForSeconds(time)); isBusy = false; if (victim != null) { victim.isBusy = false; victim.TakeDamage(Damage); } mover.RestoreMove(); }
public void MoveAgents(Vector3 point, float radius, Liver2D except) { // var result = new Collider[10]; var res = Physics2D.OverlapCircleAll(point, radius, AgentMask.value); // Physics.OverlapSphereNonAlloc(point, radius, result, AgentMask.value); //print(res.Length); foreach (var item in res) { var agent = item.GetComponent <Liver2D>(); if (agent.CanManage == false) { continue; } if (except != null && agent == except) { continue; } // todo if (!agent.isBusy) { agent.MoveTo(point); } } // fore }
/*private void FixedUpdate() * { * if(throwForce != Vector3.zero) * { * rb.AddForce(throwForce, ForceMode2D.Impulse); * throwForce = Vector3.zero; * } * }*/ public void Take(Liver2D liver) { //print("Take " + Type); rb.simulated = false; collider2d.enabled = false; transform.SetParent(liver.transform); // держим немного впереди transform.localPosition = Vector3.zero + Vector3.down * 0.2f; if (ShowOnWear) { transform.localRotation = Quaternion.identity; transform.localScale = startScale * WearingScaleRatio; AuraRender.enabled = false; } else { sr.enabled = false; AuraRender.enabled = false; } Carrier = liver; //sr.sortingOrder = 0; }
public void TakeOff(Liver2D owner, bool throwing) { //print("TakeOff " + Type); Carrier = null; collider2d.enabled = true; rb.simulated = true; if (throwing) { var force = (transform.position - owner.transform.position).normalized * 7f; throwForce = force; rb.velocity = force; /* print(force); * rb.AddForce(force, ForceMode2D.Impulse);*/ OnThrowEvent?.Invoke(); } sr.enabled = true; transform.SetParent(defaultParent); if (ShowOnWear) { transform.localScale = startScale; } AuraRender.enabled = true; }
public void TakeOff() { // print("TakeOff key"); collider2d.enabled = true; sr.enabled = true; transform.SetParent(defaultParent); Carrier = null; }
public void Take(Liver2D liver) { // print("Take " + Type); collider2d.enabled = false; transform.SetParent(liver.transform); transform.localPosition = Vector3.zero; sr.enabled = false; Carrier = liver; liver.TakeKey(this); }
private void Unblock(Liver2D liver, bool withLinked = true) { blocked = false; if (liver != null) { liver.UseKey(); } // withLinked - чтобы убрать зацикливание if (LinkedDoor != null && withLinked) { LinkedDoor.Unblock(null, false); } sr.color = Settings.Instance.GetDoorColor(KeyCardType.None); }
private IEnumerator InfectCor(Liver2D victim, float time) { // todo //victim.mover.Speed = infector.mover.Speed; LiverInteract = victim; victim.EnemyInteract = this; mover.StopMove(); victim.mover.StopMove(); isBusy = true; victim.isBusy = true; // направление mover.RotateTo(victim.transform.position); //var dir = victim.transform.position - transform.position; //float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg + 90; //transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); yield return(new WaitForSeconds(time)); isBusy = false; if (victim != null) { victim.isBusy = false; victim.InfectedBy(this); } victim.mover.RestoreMove(); if (DeadAfterInfect) { this.Dead(false); } else { this.mover.RestoreMove(); } }
private void OnCollisionEnter2D(Collision2D collision) { var enemy = collision.gameObject.GetComponent <Enemy2D>(); if (enemy != null) { Hp--; CheckHp(); } if (NeedRepair && Worker == null) { var agent = collision.gameObject.GetComponent <Liver2D>(); if (agent != null && agent.HasRepairKit) { Worker = agent; agent.mover.StopMove(); agent.isBusy = true; } } }
private void Update() { if (Worker != null) { Hp += RepairSpeed * Time.deltaTime; if (Hp >= StartHp) { Hp = StartHp; Worker.mover.RestoreMove(); Worker.isBusy = false; Worker = null; sr.sprite = defaultSprite; if (animator != null) { animator.enabled = false; } } _healthBar.UpdateHp(Hp); } }
private void OnTriggerEnter2D(Collider2D collision) { if (Visitor != null) { return; } if (!collision.gameObject.TryGetComponent <Liver2D>(out var liver)) { return; } Visitor = liver; if (NotStop) { return; } liver.mover.StopMove(); liver.isBusy = true; liver.ManageObject = this; }
private void SelectLiver(Liver2D agent) { if (agent != null && !agent.CanManage) { return; } // снять выбор с предыдущего if (selectedAgent != null && selectedAgent != agent) { selectedAgent.Manage(false); } selectedAgent = agent; if (agent != null) { agent.Manage(true); } //cameraMover.SetZoom(0.5f); }
private void OnTriggerExit2D(Collider2D collision) { if (Visitor == null || NotStop) { return; } if (!collision.gameObject.TryGetComponent <Liver2D>(out var liver)) { return; } if (Visitor != liver) { return; } Visitor.mover.RestoreMove(); // todo Visitor.isBusy = false; Visitor.ManageObject = null; Visitor = null; }
private IEnumerator LiverDeadCor(float time, Liver2D liver) { yield return(new WaitForSeconds(time)); liver?.Dead(false); }
// Update is called once per frame void LateUpdate() { if (Time.timeScale == 0) { return; } if (Input.GetMouseButtonDown(0)) { var origin = camera.ScreenToWorldPoint(Input.mousePosition); var hit = Physics2D.Raycast(origin, Vector2.zero, Distance, InteractionMask); if (hit.collider != null) { if (hit.collider.gameObject.TryGetComponent <Door2D>(out var door)) { door.Select(); } if (hit.collider.gameObject.TryGetComponent <Liver2D>(out var agent)) { SelectLiver(agent); } } else { // для более простого выбора юнита, если лучом не попали float minDist = int.MaxValue; Liver2D agent = null; var colliders = Physics2D.OverlapCircleAll(origin, pointSize, InteractionMask); if (colliders.Length > 0) { foreach (var col in colliders) { if (col.gameObject.TryGetComponent <Liver2D>(out var currAgen) == false) { continue; } var dist = (origin - transform.position).sqrMagnitude; if (dist < minDist) { agent = currAgen; minDist = dist; } } } SelectLiver(agent); } } if (Input.GetMouseButton(1)) { var origin = camera.ScreenToWorldPoint(Input.mousePosition); origin.z = 0; //print(origin); MoveAgents(origin, Radius, selectedAgent); } // бросить предмет if (Input.GetKeyDown(KeyCode.Space)) { if (selectedAgent != null /*&& selectedAgent.Equipment != null*/) { selectedAgent.ThrowEquipment(); } } cameraMover.FolowLiver = selectedAgent; }
public void SetMessage(Message message) { _text.text = message.Text; Owner = message.Owner; }