// Update is called once per frame void Update () { //RayCollision RaycastHit hit; int layerMask = ~(1 << LayerMask.NameToLayer("NoBeamHit") | 1 << 2); if (HitEffect != null && !bHit && Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity, layerMask)) { //GameObject hitobj = hit.collider.gameObject; if(hit.distance < BL.GetNowLength()) { BL.StopLength(hit.distance); bHit = true; Quaternion Angle; //Reflect to Normal if (Reflect) { Angle = Quaternion.LookRotation(Vector3.Reflect(transform.forward, hit.normal)); } else { Angle = Quaternion.AngleAxis(180.0f, transform.up) * this.transform.rotation; } GameObject obj = (GameObject)Instantiate(HitEffect,this.transform.position+this.transform.forward*hit.distance,Angle); obj.GetComponent<BeamParam>().SetBeamParam(BP); obj.transform.localScale = this.transform.localScale; } //print("find" + hit.collider.gameObject.name); } /* if(bHit && BL != null) { BL.gameObject.renderer.material.SetFloat("_BeamLength",HitTimeLength / BL.GetNextLength() + 0.05f); } */ }
// Update is called once per frame void Update() { //RayCollision RaycastHit hit; //10000000011 in base 10 int layerMask = 1027; if (HitEffect != null && !bHit && Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity, layerMask)) { GameObject hitobj = hit.collider.gameObject; if (hit.distance < BL.GetNowLength()) { BL.StopLength(hit.distance); bHit = true; Quaternion Angle; //Reflect to Normal if (Reflect) { Angle = Quaternion.LookRotation(Vector3.Reflect(transform.forward, hit.normal)); } else { Angle = Quaternion.AngleAxis(180.0f, transform.up) * this.transform.rotation; } GameObject obj = (GameObject)Instantiate(HitEffect, this.transform.position + this.transform.forward * hit.distance, Angle); obj.GetComponent <BeamParam>().SetBeamParam(BP); obj.transform.localScale = this.transform.localScale; //generate collision data if (hit.collider.gameObject.layer == 10) { Debug.Log("Hit building"); hit.collider.gameObject.GetComponent <destructable>().CollisionFaker(this.GetComponent <lazerBullet>()); } else { Debug.Log("Hit " + hit.collider.name + ", on layer: " + hit.collider.gameObject.layer); } } //print("find" + hit.collider.gameObject.name); } }