void DrawLineSeg(Vector2 position, Vector2 direction, int reflectionsRemain) { if (reflectionsRemain == 0) { if (_lightTrig != null) { _lightTrig.RemoveOneLight(this); } MoveEndParticle(position, -direction); return; } position += direction.normalized * 0.01f; RaycastHit2D hit = Physics2D.Raycast(position, direction, _maxStepDistance, _whatIsSurface); if (hit.collider) { direction = Vector2.Reflect(direction, hit.normal); position = hit.point; } else { position += direction * _maxStepDistance; } _line.positionCount++; int lineSegIndex = _maxReflectionCount - reflectionsRemain + 1; _line.SetPosition(lineSegIndex, position); reflectionsRemain--; if (hit.collider && !hit.collider.tag.Contains("Reflective")) { reflectionsRemain = 0; MoveEndParticle(position, -Vector2.Reflect(direction, hit.normal)); if (hit.collider.tag.Contains("LightTrigger")) { // open door; _lightTrig = hit.transform.GetComponent <LightTrigger>(); if (_lightTrig == null) { Debug.Log("missing lightTrig"); } else { _lightTrig.AddOneLight(this); } } else if (_lightTrig != null) { _lightTrig.RemoveOneLight(this); } return; } DrawLineSeg(position, direction, reflectionsRemain); }
//Finds the specfic light trigger in the scene and gets a reference to it //used below in the specfic update. protected override void LevelSpecificInit() { foreach (LightTrigger lightrigger in lightDoors) { if (lightrigger.name.Contains("Interact")) { lightTriggerInteract = lightrigger; } } }
private void Awake() { if (_instance != null && _instance != this) { Destroy(this.gameObject); } else { _instance = this; } }
private void CheckIfSeen(Collider c) { LightTrigger component = c.GetComponent <LightTrigger>(); if (component) { PointLightSource lightSource = component.LightSource; if (!lightSource.isEnabled) { return; } if (lightSource && lightSource.lightType == PointLightMask.LightType.PointLight) { this.Disappear(); } else if (lightSource.lightType == PointLightMask.LightType.BeamLight) { if (Vector3.Distance(base.transform.position, lightSource.beamArcCenter) < lightSource.colliderSize) { this.Disappear(); } else { float beamAngle = lightSource.beamAngle; Vector3 b = Vector3.up * c.transform.position.y + Vector3.right * c.transform.position.x; if (this.collisionPoints != null && this.collisionPoints.Count > 0) { foreach (Vector3 a in this.collisionPoints) { Vector3 from = a - b; float num = Vector3.Angle(from, lightSource.transform.up); float num2 = Vector3.Distance(a, b); if (num2 <= lightSource.baseLightSize + lightSource.borderWidth || num < beamAngle * 0.5f) { this.Disappear(); } } } else { Vector3 a2 = Vector3.up * base.transform.position.y + Vector3.right * base.transform.position.x; Vector3 from2 = a2 - b; float num = Vector3.Angle(from2, lightSource.transform.up); float num2 = Vector3.Distance(a2, b); if (num2 <= lightSource.baseLightSize + lightSource.borderWidth || num < beamAngle * 0.5f) { this.Disappear(); } } } } } }
private void OnTriggerEnter(Collider col) { if (col.gameObject.layer == 15) { SetState(LightingState.CanEnableLightHouse); currentLightTrigger = col.GetComponent<LightTrigger>(); pController.ScalePlayer(true); // print ("follow enter"); // col.GetComponent<LightTrigger>().EnableLight(); } }
//assorbe luce da una sorgente private void ControlLight() { if (Input.GetButtonDown("AbsorbLight")) //se premo il tasto destro { Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, absorbRange)) //raycast dal centro dello schermo fino a distanza absorbRange { //print("colpito qualcosa"); LightSource2 ls = hit.collider.gameObject.GetComponent <LightSource2>(); LightTrigger lt = hit.collider.gameObject.GetComponent <LightTrigger>(); if (ls) //se è una sorgente di luce { int light_amount = ls.takeLight(); if (light_amount > 0) //se è accesa --> prendo luce { Light += light_amount; if (lt) { lt.Trigger(); } } else if (Light >= ls.getLightBulletsAmount()) // se è spenta e ho munizioni --> rilascio luce { ls.PutLight(); Light -= ls.getLightBulletsAmount(); if (lt) { lt.Trigger(); } } } } if (Physics.Raycast(ray, out hit, doorOpenRange)) //secondo raycast più corto per vedere se posso aprire una porta { UnlockedDoor ud = hit.collider.gameObject.GetComponent <UnlockedDoor>(); if (ud) { ud.Open(); } } } }
public void SetLightOnTrigger(LightTrigger trigger) { try { if (IsConnected) { byte[] rgb = new byte[] { (byte)CommandType.LightOnTrigger, (byte)trigger }; _bluetoothSocket.OutputStream.Write(rgb, 0, 2); _bluetoothSocket.OutputStream.Flush(); } else { throw new Exception("Could not send. Bluetooth device is not connected"); } } catch (Exception ex) { Disconnect(); throw new Exception($"Could set light on trigger. Please connect again.\n {ex.Message}. "); } }
private void CheckIfSeen(Collider c) { if (this.disabled || WPFMonoBehaviour.levelManager.gameState == LevelManager.GameState.Completed) { return; } LightTrigger component = c.GetComponent <LightTrigger>(); if (component) { PointLightSource lightSource = component.LightSource; if (lightSource && lightSource.lightType == PointLightMask.LightType.PointLight) { this.Collect(); } else if (lightSource.lightType == PointLightMask.LightType.BeamLight) { if (Vector3.Distance(base.transform.position, lightSource.beamArcCenter) < lightSource.colliderSize) { this.Collect(); } else { float beamAngle = lightSource.beamAngle; Vector3 a = Vector3.up * base.transform.position.y + Vector3.right * base.transform.position.x; Vector3 b = Vector3.up * c.transform.position.y + Vector3.right * c.transform.position.x; Vector3 from = a - b; float num = Vector3.Angle(from, lightSource.transform.up); if (num < beamAngle * 0.5f) { this.Collect(); } } } } }
private void Start() { lights = FindObjectOfType <LightTrigger>(); }