Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //movement
        Vector3 movement = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));

        movement.Normalize();

        pc.Move(movement * movementSpeed);

        //aiming
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Vector3    aimPoint;

        if (Physics.Raycast(ray, out hit))
        {
            aimPoint = hit.point;
            aimPoint = new Vector3(aimPoint.x, transform.position.y, aimPoint.z);

            transform.LookAt(aimPoint);

            gc.AimGun(aimPoint);
        }

        //shooting
        if (Input.GetMouseButton(0))
        {
            //print ("Shooting");
            gc.TriggerPulled();
        }
        else if (Input.GetMouseButtonUp(0))
        {
            gc.TriggerReleased();
        }

        //changing weapons
        if (Input.mouseScrollDelta.y != 0)
        {
            gc.ScrollWeapon((int)Input.mouseScrollDelta.y);
        }

        if (Input.GetButtonDown("Cancel"))
        {
            SceneManager.LoadScene("menu");
        }
    }
Ejemplo n.º 2
0
    // Checks to see if zombies are nearby, for self-defense
    void SeekNearbyInterests()
    {
        // Update the target
        if (target == null || target.tag != "Enemy" || target.tag != "DroppedItem")
        {
            // If the class can fight, see if any enemies are nearby
            if (database.specialisations[survivor.specialisationID].killVisibleEnemies || database.specialisations[survivor.specialisationID].moveToHiddenEnemies)
            {
                target = FindClosestInRange("Enemy", database.specialisations[survivor.specialisationID].viewRange);
            }
            // If there are no enemies and the class can pickup items, find some
            if (target == null && database.specialisations[survivor.specialisationID].pickupNearbyItems)
            {
                target = FindClosestInRange("DroppedItem", database.specialisations[survivor.specialisationID].viewRange);
            }
        }

        // Do we have enough HP or should we retreat?
        float retreatHP = (livingEntity.startingHealth / 100) * database.specialisations[survivor.specialisationID].retreatPercentage;

        if (livingEntity.Health < retreatHP)
        {
            // Time to retreat
            if (database.specialisations[survivor.specialisationID].retreatZone != null)
            {
                retreating             = true;
                unit.target            = database.specialisations[survivor.specialisationID].retreatZone;
                unit.moveTowardsTarget = true;
            }
            else
            {
                retreating = false;
                Debug.LogError(gameObject.name + " is trying to retreat, but " + database.specialisations[survivor.specialisationID].specialisationName + " has no retreat zone set!");
            }
        }
        else
        {
            retreating = false;
        }

        // If there is a target
        if (target != null && !retreating)
        {
            // If the target is an enemy
            if (target.transform.tag == "Enemy")
            {
                // Can we see the enemy?
                transform.LookAt(target.transform);

                bool       canSee = true;
                RaycastHit hit;
                if (Physics.Raycast(transform.position, transform.forward, out hit, database.specialisations[survivor.specialisationID].viewRange, LayerMask.GetMask("Unwalkable")))
                {
                    if (hit.distance < Vector3.Distance(transform.position, target.transform.position))
                    {
                        canSee = false;
                    }

                    // We can't see the enemy
                    if (!canSee && database.specialisations[survivor.specialisationID].moveToHiddenEnemies)
                    {
                        unit.target            = target;
                        unit.moveTowardsTarget = true;
                    }
                }

                if (canSee)
                {
                    // We can see the enemy
                    if (database.specialisations[survivor.specialisationID].killVisibleEnemies || database.specialisations[survivor.specialisationID].moveToHiddenEnemies)
                    {
                        unit.moveTowardsTarget = false;
                        if (!gunController.EquippedGun.Reloading)
                        {
                            gunController.AimGun(target.transform.position);
                            gunController.Shoot();
                        }
                    }
                    else
                    {
                        unit.moveTowardsTarget = true;
                    }
                }
            }

            // If the target is an item
            else if (target.transform.tag == "DroppedItem")
            {
                if (database.specialisations[survivor.specialisationID].pickupNearbyItems)
                {
                    unit.target            = target;
                    unit.moveTowardsTarget = true;
                }
            }

            // Else, just move towards the destination
            else
            {
                unit.moveTowardsTarget = true;
            }
        }
    }