Ejemplo n.º 1
0
    void OnTriggerStay(Collider col)
    {
        if (enemy == null)
        {
            //return;
        }
        if (target == null || col.transform == target)
        {
            if (col.tag == "SquadMan")
            {
                RaycastHit hit;
                //raycast towards them
                Vector3 dir   = col.transform.position - transform.parent.position;
                Vector3 aimUp = transform.parent.up * 0.8f;

                SquadMember testCrouch = col.GetComponent <SquadMember>();

                if (testCrouch != null && testCrouch.GetCrouch())
                {
                    aimUp *= 0.0f;
                }

                Physics.Raycast(transform.parent.position + aimUp, dir, out hit);

                if (hit.collider != null && hit.collider.tag == "SquadMan")
                {
                    //enemy can be seen, shoot them
                    target = hit.collider.transform;
                    if (target == null)
                    {
                        Debug.Log("internal screaming");
                    }
                    enemy.SetTarget(target);
                    //gun.LookAt(hit.collider.transform);

                    //Destroy(hit.collider.gameObject);
                }
            }
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        update += 500.0f * Time.deltaTime;

        if (update >= 500.0f)
        {
            update = 0.0f;
            if (target != null)
            {
                enemy.SetTarget(target);

                RaycastHit hit;
                //raycast towards them
                Vector3 dir   = target.position - transform.parent.position;
                Vector3 aimUp = transform.parent.up * 0.8f;

                SquadMember testCrouch = target.GetComponent <SquadMember>();

                if (testCrouch != null && testCrouch.GetCrouch())
                {
                    aimUp *= 0.0f;
                }

                Physics.Raycast(transform.parent.position + aimUp, dir, out hit);

                if (hit.collider != null && hit.collider.gameObject.tag != "SquadMan")
                {
                    target = null;
                    enemy.SetTarget(null);
                }
            }
            else
            {
                enemy.SetTarget(null);
                //gun.transform.localRotation = Quaternion.identity;
            }
        }
    }