Example #1
0
    void OnTriggerEnter(Collider other)
    {
        // Hit by light
        if (other.gameObject.GetComponent <LightUnit> ())
        {
            LightUnit lightUnit = other.gameObject.GetComponent <LightUnit> ();

            if (lightUnit.isNormal())
            {
                Vector3    inputVector = other.gameObject.GetComponent <Rigidbody> ().velocity;
                Color      inputColor  = other.gameObject.GetComponent <LightUnitColorManager> ().lightColor;
                GameObject newObject   = Instantiate(other.gameObject, transform.position, Quaternion.identity);
                newObject.GetComponent <Rigidbody> ().velocity = inputVector;
                Color outputColor = inputColor;

                outputColor.r = (filterColor.r == 0f) ? 0f : inputColor.r;
                outputColor.g = (filterColor.g == 0f) ? 0f : inputColor.g;
                outputColor.b = (filterColor.b == 0f) ? 0f : inputColor.b;

                newObject.GetComponent <LightUnitColorManager> ().lightColor = outputColor;

                lightUnit.kill();
            }
        }
    }
    void OnTriggerEnter(Collider other)
    {
        // Hit by light
        if (other.gameObject.GetComponent <LightUnit> ())
        {
            LightUnit lightUnit = other.gameObject.GetComponent <LightUnit> ();

            if (lightUnit.isNormal())
            {
                Vector3 normalVector = glass.transform.localRotation * Vector3.right;
                Vector3 inputVector  = other.gameObject.GetComponent <Rigidbody> ().velocity;
                // Debug.Log ("Normal = " + normalVector.ToString ());
                // Debug.Log ("Input = " + inputVector.ToString ());

                Quaternion normalQuaternion = Quaternion.FromToRotation(inputVector, normalVector);
                // Debug.Log ("Q = " + normalQuaternion.eulerAngles.ToString());
                Vector3 outputVector = -(normalQuaternion * (normalQuaternion * inputVector));
                // Debug.Log ("Output = " + outputVector.ToString ());

                if ((outputVector - inputVector).magnitude >= 1)
                {
                    GameObject newObject = Instantiate(other.gameObject, transform.position, Quaternion.identity);
                    newObject.GetComponent <Rigidbody> ().velocity = outputVector;
                }
                lightUnit.kill();
            }
        }
    }
    void OnTriggerEnter(Collider other)
    {
        LightUnit lightUnit = other.gameObject.GetComponent <LightUnit> ();

        if (lightUnit && lightUnit.isNormal())
        {
            if (!penetrateLight)
            {
                lightUnit.kill();
            }
            if (openTime < 0.0f)
            {
                AudioSource.PlayClipAtPoint(hitSound, Camera.main.transform.position);
            }
            openTime = 1.0f;
        }
    }