Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        AIState state = getState();

        switch (state)
        {
        case AIState.ATTACK:
            if (!animation.IsPlaying("attack02"))
            {
                animation.Play("attack02");
            }

            RaycastHit ray = RayCast.Raycast(transform, player, 3);

            if (ray.transform.gameObject.tag == "Player")
            {
                playerScript.TakeDamage(50);
            }
            ai.canMove = false;
            break;

        case AIState.CHASE:
            ai.canMove   = true;
            ai.canSearch = true;
            if (!animation.IsPlaying("run"))
            {
                animation.Play("run");
            }
            break;

        case AIState.WALK_AROUND:
            // to do
            animation.PlayQueued("walk02");
            ai.canSearch = false;
            break;

        case AIState.DEAD:
            if (!dead)
            {
                animation.Play("death"); dead = true;
            }
            ai.canSearch = false;
            break;

        case AIState.IDLE:
            if (!animation.IsPlaying("idle"))
            {
                animation.Play("idle");
            }
            ai.canSearch = false;
            break;
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Use"))
        {
            Debug.Log("Door");

            RaycastHit hit = RayCast.Raycast(player, 5);

            if (hit.transform.gameObject.tag == "Door")
            {
                Application.LoadLevel(level);
            }
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (health <= 0)
        {
            Time.timeScale     = 0;
            chMotor.canControl = false;
            return;
        }

        //float vScale = 1.0f;
        float speed = walkSpeed;

        if (Input.GetButton("Fire1"))
        {
            string anim = (zoomed) ? "shoot_zoom" : "shoot";

            if (!anims.IsPlaying(anim) && anims.Play(anim))
            {
                RaycastHit hit = RayCast.Raycast(GameObject.Find("flashlight").transform, 100);

                GameObject objHit = hit.transform.gameObject;

                ZombieAI zombie = objHit.GetComponentInParent <ZombieAI>();

                if (!zombie.isDead())
                {
                    if (objHit.tag == "ZombieHead")
                    {
                        zombie.TakeDamage(60);
                    }
                    if (objHit.tag == "ZombieCollider")
                    {
                        zombie.TakeDamage(40);
                    }
                }
            }
        }

        if (Input.GetButton("Sprint") && !crouching)
        {
            speed = runSpeed;
        }

        if (Input.GetButtonDown("Crouch"))
        {
            crouching = !crouching;
        }

        if (Input.GetButton("Reload") || (Input.GetButton("Crouch") && Input.GetButton("Reload")))
        {
            if (zoomed)
            {
                anims.Play("unzoom");
                anims.PlayQueued("reload");
                zoomed = false;
            }
            anims.Play("reload");
        }

        if (anims.IsPlaying("reload"))
        {
            reloading = true;
        }
        else
        {
            reloading = false;
        }

        if (Input.GetMouseButton(1))
        {
            if (zoomed || reloading)
            {
                return;
            }
            anims.Play("zoom");
            zoomed = true;
        }
        else
        {
            if (!zoomed)
            {
                return;
            }
            anims.Play("unzoom");
            zoomed = false;
        }

        chMotor.movement.maxForwardSpeed = speed;
        if (!anims.IsPlaying("shoot") && !anims.IsPlaying("shoot_zoom") && !anims.IsPlaying("reload") && !anims.IsPlaying("unzoom") && !anims.IsPlaying("zoom"))
        {
            anims.Play("idle");
        }
    }