Example #1
0
    private void OnTriggerExit2D(Collider2D col)
    {
        PropertyFrozen f = col.gameObject.GetComponent <PropertyFrozen>();

        if (f != null)
        {
            f.StayFrozen(false);
        }
    }
Example #2
0
    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);
        }
    }