Example #1
0
    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);
        }
    }
Example #2
0
    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();
        }
    }
Example #3
0
    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();
        }
    }