Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButton("Fire1"))
     {
         if (!isFiring && !isReloading)
         {
             if (Time.time > lastFireTime + 1 / props.getRof())
             {
                 if (cgl.cheatActivated)
                 {
                     Fire();
                 }
                 else
                 {
                     Shoot();
                 }
             }
         }
     }
     if (Input.GetButton("Melee"))
     {
         melee.Attack();
     }
     if (Input.GetButton("Reload"))
     {
         if (!isReloading)
         {
             if (Time.time > lastFireTime + 1 / props.getRof())
             {
                 Reload();
             }
         }
     }
 }
Ejemplo n.º 2
0
 void Update()
 {
     if (target)
     {
         Move();
         if (properties.stopDistance >= playerDistance && Time.time >= nextAttackTime)
         {
             meleeController.Attack(damageable, properties.damage, target.position, properties.attackSpeed);
             nextAttackTime = Time.time + properties.timeBetweenAttack;
         }
     }
 }
Ejemplo n.º 3
0
    void Update()
    {
        //Movement input
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSPeed;

        controller.Move(moveVelocity);

        //Look input
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);

        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
            controller.LookAt(point);
            croshairs.transform.position = point;
            croshairs.DetectTargets(ray);

            //Amiming fix
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1.5)
            {
                gunController.Aim(point);
            }
        }

        //Weapon input
        if (Input.GetMouseButton(0))
        {
            gunController.OnTriggerHold();
        }

        if (Input.GetMouseButtonUp(0))
        {
            gunController.OnTriggerRelease();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            gunController.Reload();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            meleeController.Attack();
        }

        if (Input.GetAxis("Mouse ScrollWheel") > 0f) // forward
        {
            gunController.EquipNextGun();
        }
        else if (Input.GetAxis("Mouse ScrollWheel") < 0f) // backwards
        {
            gunController.EquipPreviousGun();
        }

        //Fall death
        if (transform.position.y < -10)
        {
            TakeDamage(health);
        }
    }