Example #1
0
    //Here's a bonus function!
    // We can put code here that we want to trigger when our character touches something (anything right now!)
    #endregion

    private void CastRay()
    {
        #region weapon firing ray
        //Raycast for weapon targeting.
        trajectory = new Ray(transform.position + new Vector3(0.0f, 0.608f, 0.0f), Camera.main.transform.forward);
        Debug.DrawRay(trajectory.origin, trajectory.direction * 100, Color.blue, 2, false);
        fireAgain = false;
        if (Physics.Raycast(trajectory, out targetpoint, Mathf.Infinity, layerMask) && targetpoint.collider != null)
        {
            heatCurrent       -= heatCost;
            instantiationPoint = targetpoint.point;
            //First checks to see if a navmesh actor was shot directly
            if (targetpoint.transform.gameObject.tag == "Foe")
            {
                Instantiate(bullet, instantiationPoint, Quaternion.identity);
                currentTarget             = targetpoint.transform.gameObject.GetComponent <HasBeenShot>();
                currentTarget.hasBeenShot = true;
                fadeIn = true;
            }
            //using what I've learned from the ground detection spherecast, and the other raycasts I've used so far...
            else if (Physics.SphereCast(transform.position, 0.3f, Camera.main.transform.forward, out additionalHitscan, targetpoint.distance, enemyMask))
            {
                //I've created bullet magnetism.
                if (additionalHitscan.transform.gameObject.tag == "Foe")
                {
                    Debug.Log("Bullet Magnetism struck target");
                    Instantiate(bullet, additionalHitscan.point, Quaternion.identity);
                    currentTarget             = additionalHitscan.transform.gameObject.GetComponent <HasBeenShot>();
                    currentTarget.hasBeenShot = true;
                    fadeIn = true;
                }
            }
            else
            {
                //Debug.Log("I hit something!");
                //Debug.Log("At " + instantiationPoint.x + ", " + instantiationPoint.y + ", " + instantiationPoint.z);
                if (targetpoint.transform.gameObject.tag == "Target")
                {
                    Instantiate(bullet, instantiationPoint, Quaternion.identity);
                    fadeIn = true;
                }
            }

            //This one's for AoE considerations, checks I haven't hit anything near the blast radius.
            //Advance Higher mechanics really pulling through for me, now.
            AoeFinder = instantiationPoint - (2.2f * new Vector3(instantiationPoint.x - transform.position.x, instantiationPoint.y - transform.position.y, instantiationPoint.z - transform.position.z).normalized);
            if (Physics.SphereCast(AoeFinder, 1.1f, Camera.main.transform.forward, out additionalHitscan, 2.2f, enemyMask))
            {
                if (additionalHitscan.transform.gameObject.tag == "Foe")
                {
                    //This will get flagged even if an enemy is shot directly
                    Debug.Log("Caught additional target");
                    currentTarget             = additionalHitscan.transform.gameObject.GetComponent <HasBeenShot>();
                    currentTarget.hasBeenShot = true;
                }
            }
        }
        #endregion
    }
 void Start()
 {
     HasBeenShot = familyDisappointment.GetComponent <HasBeenShot>();
     Type1Move   = familyDisappointment.GetComponent <Type1Move>();
 }