private void OnTriggerExit2D(Collider2D col) { PropertyFrozen f = col.gameObject.GetComponent <PropertyFrozen>(); if (f != null) { f.StayFrozen(false); } }
private void OnTriggerEnter2D(Collider2D col) { if (!enabled) { return; } //creat frosted Ice when walking on water if (CheckLayerIsInTheLayerMask(col.gameObject.layer, water)) { if (frozenWater.Contains(col.gameObject)) { return; //already did the ice instantiation. } if (icePrefab == null) { Debug.LogError(GetType().Name + " error: trying to instantiate ice while icePrefab not selected."); return; } Rigidbody2D rb = GetComponent <Rigidbody2D>(); if (rb) { rb.velocity -= new Vector2(0, rb.velocity.y); } transform.position += new Vector3(0, heightTuning * 1.3f); //this help ice effect work normally //create an ice Vector3 p = new Vector3( col.transform.position.x, col.bounds.ClosestPoint(transform.position).y + heightTuning); GameObject ice = Instantiate(icePrefab, p, Quaternion.Euler(0, 0, 0)) as GameObject; float iceLocalLength = col.bounds.size.x / ice.transform.lossyScale.x; ice.transform.localScale = new Vector3(iceLocalLength, ice.transform.localScale.y); ice.transform.SetParent(col.transform); //Debug.Log("An ice " + ice.name + " has been instantiated."); //create finished. frozenWater.Add(col.gameObject); } PropertyFrozen f = col.gameObject.GetComponent <PropertyFrozen>(); if (f != null) { //Debug.Log("Ready to set stay frozen"); f.StayFrozen(true); } }
private void OnCollisionStay2D(Collision2D col) { if (!enabled) { return; } if (ignoreTheseObjects == (ignoreTheseObjects | (1 << col.gameObject.layer))) { return; } PropertyFrozen p = col.gameObject.GetComponent <PropertyFrozen>(); if (p) { p.Melt(meltingIcePeriod); } }
public void ShootLaser(Vector3 StartPosition, Vector3 Direction) { //Debug.Log("shoot"); laserLine.positionCount = 2; laserLine.SetPosition(0, StartPoint.position); RaycastHit2D hit; if (UseDirection) { hit = Physics2D.Raycast(StartPosition, Direction, Mathf.Infinity); } else { Vector2 l = new Vector2(this.transform.position.x, this.transform.position.y); hit = Physics2D.Raycast(StartPosition, new Vector2(endPoint.transform.position.x - l.x, endPoint.transform.position.y - l.y), Mathf.Infinity); } bool needToReset = false; laserLine.SetPosition(1, hit.point); GameObject hitObj = null; //Debug.Log (hit.collider.name); if (hit.collider != null) { hitObj = hit.collider.gameObject; } if (hitObj != lastHittingObj || hitObj == null) { needToReset = true; lastHittingObj = hitObj; } if (hitObj != null) { if (hitObj.tag == "Floor") { } else if (hitObj.tag == "Player") { PropertyFrosting frosting = hitObj.GetComponent <PropertyFrosting>(); //PropertyMetal metal = hitObj.GetComponent<PropertyMetal>(); Player p = hitObj.GetComponent <Player>(); if (frosting) { laserLine.SetPosition(1, hit.point); } else { p.Death(); } } else { laserLine.SetPosition(1, hit.point); PropertyManager objPropertyManager = hitObj.GetComponent <PropertyManager>(); //Debug.Log("Have got property manager of " + hitObj.name + ": " + (objPropertyManager!=null)); if (objPropertyManager != null) { PropertyFrozen frozenProperty = objPropertyManager.GetProperty <PropertyFrozen>(); if (frozenProperty) { timer_f += Time.deltaTime * 2; //DEV NOTE: the nasty sol. of Unity's broken collision detect. if (frozenProperty.immortalize) { timer_f = 0; //DEV NOTE: the nasty sol. of strange setting of Laser. } if (timer_f >= meltingIcePeriod) { frozenProperty.Melt(); } } if (objPropertyManager.GetProperty <PropertyWooden>()) { timer_w += Time.deltaTime; Pos = hitObj.transform.position; if (Pos == lastPos) { timer_w += Time.deltaTime; } else { timer_w = 0; } if (timer_w >= DestroyWoodPeriod) { Destroy(hitObj); timer_w = 0; } lastPos = Pos; } //if (objPropertyManager.GetProperty<PropertyMetal>()) //{ // Reflect(); //} } } } if (needToReset) { ResetEffect(); } }
protected void Update() { laserLine.positionCount = 2; Vector2 pos = new Vector2((this.transform.position.x + this.transform.localScale.y * 0.49f * Mathf.Sin(this.transform.eulerAngles.z / 180f * Mathf.PI)), (this.transform.position.y - this.transform.localScale.y * 0.49f * Mathf.Cos(this.transform.eulerAngles.z / 180f * Mathf.PI))); //float k = endPoint.transform.position.y > this.transform.position.y ? this.transform.position.y + 0.225f : this.transform.position.y - 0.225f; //Debug.Log(Mathf.Cos(this.transform.rotation.z / 180f * Mathf.PI)); //Debug.Log (this.transform.rotation); laserLine.SetPosition(0, pos); laserLine.SetPosition(1, endPoint.transform.position); Vector2 l = new Vector2((this.transform.position.x + this.transform.localScale.y * 0.501f * Mathf.Sin(this.transform.eulerAngles.z / 180f * Mathf.PI)), (this.transform.position.y - this.transform.localScale.y * 0.501f * Mathf.Cos(this.transform.eulerAngles.z / 180f * Mathf.PI))); RaycastHit2D hit = Physics2D.Raycast(l, new Vector2(endPoint.transform.position.x - l.x, endPoint.transform.position.y - l.y), Vector2.Distance(l, endPoint.transform.position)); bool needToReset = false; //Debug.Log (hit.collider.name); GameObject hitObj = null; if (hit.collider != null) { hitObj = hit.collider.gameObject; } if (hitObj != lastHittingObj || hitObj == null) { needToReset = true; lastHittingObj = hitObj; } if (hitObj != null) { if (hitObj.tag == "Floor") { } else if (hitObj.tag == "Player") { PropertyFrosting frosting = hitObj.GetComponent <PropertyFrosting>(); //PropertyMetal metal = hitObj.GetComponent<PropertyMetal>(); Player p = hitObj.GetComponent <Player>(); if (frosting) { laserLine.SetPosition(1, hit.point); } else { p.Death(); } } else { laserLine.SetPosition(1, hit.point); PropertyManager objPropertyManager = hitObj.GetComponent <PropertyManager>(); //Debug.Log("Have got property manager of " + hitObj.name + ": " + (objPropertyManager!=null)); if (objPropertyManager != null) { PropertyFrozen frozenProperty = objPropertyManager.GetProperty <PropertyFrozen>(); if (frozenProperty) { timer_f += Time.deltaTime * 2; //DEV NOTE: the nasty sol. of Unity's broken collision detect. if (frozenProperty.immortalize) { timer_f = 0; //DEV NOTE: the nasty sol. of strange setting of Laser. } if (timer_f >= meltingIcePeriod) { frozenProperty.Melt(); } } if (objPropertyManager.GetProperty <PropertyWooden>()) { timer_w += Time.deltaTime; Pos = hitObj.transform.position; if (Pos == lastPos) { timer_w += Time.deltaTime; } else { timer_w = 0; } if (timer_w >= DestroyWoodPeriod) { Destroy(hitObj); timer_w = 0; } lastPos = Pos; } //if (objPropertyManager.GetProperty<PropertyMetal>()) //{ // Reflect(); //} } } } if (needToReset) { ResetEffect(); } }