private void OnTriggerExit2D(Collider2D other) { if (other.tag == "Teleport") { objTeleport = null; } else if (other.tag == "ObjectivePlace") { objectivePlaceObj = null; } else if (other.tag == "HidePlace") { hidePlace = null; } }
void OnTriggerStay2D(Collider2D other) { if (other.tag == "ObjectivePlace") { objectivePlaceObj = other.gameObject; } else if (other.tag == "Kid") { if (other.transform.parent.GetComponent <Kid>().currentState != Kid.states.HIDE) { kidInteract = other.transform.parent.gameObject; } } else if (other.tag == "HidePlace") { HidePlace auxHidPlace = other.GetComponent <HidePlace>(); hidePlace = auxHidPlace; } }
private void Hide() { countTime -= Time.deltaTime; if (Random.Range(0, 100000) > 95000 && countTime < 0) { if ((!SeePlayerBackward(2.5f) && !SeePlayerForward(2.5f)) || hidePlayerSee) { countTime = Random.Range(0f, 1.5f); sprRenderer.enabled = true; currentState = states.IDLE; hidePlace.kid = null; hidePlace = null; } } vel.x = Vector3.zero.x; vel.y = rb2D.velocity.y; rb2D.velocity = vel; }
/// <summary> /// Sent when another object enters a trigger collider attached to this /// object (2D physics only). /// </summary> /// <param name="other">The other Collider2D involved in this collision.</param> void OnTriggerEnter2D(Collider2D other) { if (canMove) { if (other.tag == "Teleport") { if (Random.Range(0, 100000) > 50000 && isRun) { isRun = false; detectCollider.enabled = false; other.GetComponent <Teleport>().ChangePlace(this); } } else if (other.tag == "HidePlace") { int offset = 0; if (!SeePlayerBackward(8f) && !SeePlayerForward(8f)) { offset = 25000; } if (Random.Range(0, 100000) > (90000 - offset) && isRun && !other.GetComponent <HidePlace>().kid) { if (SeePlayerBackward(3.5f) && SeePlayerForward(3.5f)) { hidePlayerSee = true; } isRun = false; currentState = states.HIDE; countTime = Random.Range(10f, 15f); sprRenderer.enabled = false; hidePlace = other.GetComponent <HidePlace>(); hidePlace.Hide(this); } } } }
public void HideObject(GameObject objectToHide, HidePlace hidePlace) { var hideInfo = new HideInfo() { Object = objectToHide, ShowAlpha = objectToHide.Alpha, ShowPosition = objectToHide.Position, HidePlace = hidePlace, HideAction = HideAction.Nothing, Timer = 0 }; var hideRect = new Rectangle( (int)(ParentRoom.Position.X - ParentRoom.InGameOffsetX), (int)(ParentRoom.Position.Y - ParentRoom.InGameOffsetY), (int)(ParentRoom.Size.X + 2 * ParentRoom.InGameOffsetX), (int)(ParentRoom.Size.Y + 2 * ParentRoom.InGameOffsetY)); var hideOffset = 10; switch (hidePlace) { case HidePlace.Top: hideInfo.HidePosition = new Vector2(objectToHide.Position.X, hideRect.Y - objectToHide.Size.Y - hideOffset); break; case HidePlace.Bottom: hideInfo.HidePosition = new Vector2(objectToHide.Position.X, hideRect.Y + hideRect.Size.Y + hideOffset); break; case HidePlace.Left: hideInfo.HidePosition = new Vector2(hideRect.X - objectToHide.Size.X - hideOffset, objectToHide.Position.Y); break; case HidePlace.Right: hideInfo.HidePosition = new Vector2(hideRect.X + hideRect.Size.X + hideOffset, objectToHide.Position.Y); break; } objectsToHide.Add(hideInfo); }