Ejemplo n.º 1
0
    void Update()
    {
        transform.forward = player.transform.forward;
        if (Time.time > nextFire)
        {
            nextFire = Time.time + Random.Range(fireRateMin, fireRateMax);


            RaycastHit hit;
            rayOrigin.transform.LookAt(player.transform.position);
            Ray rayTest = new Ray(rayOrigin.transform.position, rayOrigin.transform.forward);

            if (Physics.Raycast(rayTest, out hit, 100f))
            {
                Debug.DrawRay(rayOrigin.transform.position, rayOrigin.transform.forward * 100, Color.blue);
                if (hit.collider.tag == "Player")
                {
                    float acc = Random.Range(0, 100);
                    if (acc < 80)
                    {
                        playerScript.TakeDamage(Random.Range(0, 15));
                    }
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        transform.forward = player.transform.forward;
        if (triggered)
        {
            anim.SetBool("BaddieTriggered", true);
            //Debug.Log(Vector3.Distance(transform.position, player.transform.position));
            if (Vector3.Distance(transform.position, player.transform.position) <= range)
            {
                anim.SetBool("BaddieWalking", false);
                agent.destination = transform.position;
                if (Time.time > nextFire)
                {
                    float acc = Random.Range(0, 100);
                    nextFire = Time.time + Random.Range(fireRateMin, fireRateMax);
                    anim.SetTrigger("BaddieShoot");



                    //raycast goes here
                    RaycastHit hit;
                    rayOrigin.transform.LookAt(player.transform.position);
                    Ray rayTest = new Ray(rayOrigin.transform.position, rayOrigin.transform.forward);
                    if (Physics.Raycast(rayTest, out hit, 100f))
                    {
                        Debug.DrawRay(rayOrigin.transform.position, rayOrigin.transform.forward * 100, Color.blue);
                        //Debug.Log("Seen");
                        if (hit.collider.tag == "Player")
                        {
                            if (acc < 80)
                            {
                                playerScript.TakeDamage(10);
                            }
                        }
                    }
                }
            }
            else
            {
                agent.destination = player.transform.position;
                anim.SetBool("BaddieWalking", true);
            }
        }
    }