Example #1
0
    void OnTriggerEnter(Collider other)
    {
        ParticleSystem burstVFX     = Instantiate(burstEffect, transform.position, Quaternion.identity) as ParticleSystem;
        var            burstSetting = burstVFX.main;

        burstSetting.startColor = projectileColor;
        burstVFX.Play();

        RaycastHit hit;
        Vector3    velocity          = GetComponent <Rigidbody> ().velocity.normalized;
        Vector3    rayDir            = Vector3.Lerp(velocity, Random.onUnitSphere, 0.49f);
        float      hardCodedDistance = 0.5f;
        Vector3    origin            = transform.position - velocity * hardCodedDistance;

        //Vector3
        if (Physics.Raycast(origin, rayDir, out hit, 100))
        {
            Vector2 hitCoord;
            if (hit.collider is MeshCollider)
            {
                hitCoord = hit.textureCoord2;
            }
            else
            {
                hitCoord = hit.textureCoord;
            }
            CanvasBehavior canvas = hit.collider.gameObject.GetComponent <CanvasBehavior> ();
            if (canvas != null)
            {
                canvas.ProjectileDraw(ProjectileManager.SplashAlphaInfo, projectileColor, hitCoord);
            }
            SpawnChildren(hit, velocity);
        }
        Destroy(gameObject);
    }