예제 #1
0
 public void StartReload(float reload, scr_ammo ammo)
 {
     _ReloadTime     = reload;
     _Img.fillAmount = 0;
     StopAllCoroutines();
     ammo.ReloadStart();
     _AmmoText.text = ammo.GetAmmoInClip() + "/" + ammo.GetCurrentAmmoToString();
     StartCoroutine(Reload(ammo));
 }
예제 #2
0
    IEnumerator Reload(scr_ammo ammo)
    {
        float time = 0;

        while (time < _ReloadTime)
        {
            time += Time.deltaTime;
            float progress = Mathf.Lerp(0, 1, time / _ReloadTime);
            _Img.fillAmount = progress;
            yield return(null);
        }
        ammo.ReloadEnd();
        _AmmoText.text = ammo.GetAmmoInClip() + "/" + ammo.GetCurrentAmmoToString();

        yield return(new WaitForSeconds(0.1f));

        _Img.fillAmount = 0;
    }
예제 #3
0
 // Start is called before the first frame update
 void Awake()
 {
     _Anim          = GetComponent <Animator>();
     _Hips          = _Anim.GetBoneTransform(HumanBodyBones.Hips);
     _Spine         = _Anim.GetBoneTransform(HumanBodyBones.Spine);
     _CC            = GetComponent <CharacterController>();
     _RArm          = _Anim.GetBoneTransform(HumanBodyBones.RightShoulder);
     _LArm          = _Anim.GetBoneTransform(HumanBodyBones.LeftShoulder);
     _RHand         = _Anim.GetBoneTransform(HumanBodyBones.RightHand);
     _LHand         = _Anim.GetBoneTransform(HumanBodyBones.LeftHand);
     _ShotFiring    = false;
     _Ammo          = GetComponent <scr_ammo>();
     _AmmoText      = GameObject.FindGameObjectWithTag("AmmoText").GetComponent <TextMeshProUGUI>();
     _AS            = GetComponent <AudioSource>();
     _AmmoText.text = _Ammo.GetAmmoInClip() + "/" + _Ammo.GetCurrentAmmoToString();
     _AimPlane      = new Plane(Vector3.up, Vector3.zero);
     _Dashbar       = GameObject.FindGameObjectWithTag("Dashbar").GetComponent <scr_dashbar>();
     _Health        = GetComponent <scr_health>();
 }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        #region Movement
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical   = Input.GetAxisRaw("Vertical");

        // Make movementt animation match body orientation instead of movement keys

        if (_Hips.localEulerAngles.y > 44 && _Hips.localEulerAngles.y < 152)
        {
            // Right
            _Anim.SetFloat("AxisV", horizontal);
            _Anim.SetFloat("AxisH", vertical);
        }
        else if (_Hips.localEulerAngles.y < 323 && _Hips.localEulerAngles.y > 274)
        {
            // Left
            _Anim.SetFloat("AxisV", -horizontal);
            _Anim.SetFloat("AxisH", vertical);
        }
        else if (_Hips.localEulerAngles.y > 170 && _Hips.localEulerAngles.y < 205)
        {
            _Anim.SetFloat("AxisV", -vertical);
            _Anim.SetFloat("AxisH", horizontal);
        }
        else
        {
            _Anim.SetFloat("AxisV", vertical);
            _Anim.SetFloat("AxisH", horizontal);
        }


        if (_CC.isGrounded || _CurrentDashMulti > 1)
        {
            Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
            if (direction.magnitude >= 0.1f)
            {
                _CC.Move(direction * GetSpd() * Time.deltaTime);
                // _Anim.blendt
            }
        }
        else
        {
            _CC.Move(Vector3.up * Physics.gravity.y * Time.deltaTime);
        }
        #endregion

        if (_CC.isGrounded)
        {
            _PositionResetting = false;
            _LastGrounded      = transform.position;
        }

        if (Input.GetButtonDown("Fire1") && !_ShotFiring && !_Ammo.GetIsReloading() && Time.timeScale != 0)
        {
            if (_Ammo.GetAmmoInClip() > 0)
            {
                if (_Ammo.GetAmmoInClip() <= Mathf.CeilToInt((float)_Ammo.GetClipAmmo() / 4f))
                {
                    _AS.pitch = Mathf.Lerp(3, 1, (float)_Ammo.GetAmmoInClip() / (float)_Ammo.GetClipAmmo());
                }
                else
                {
                    _AS.pitch = 1;
                }
                _Ammo.SubtractAmmo(1);
                _AmmoText.text = _Ammo.GetAmmoInClip() + "/" + _Ammo.GetCurrentAmmoToString();
                StartCoroutine(FireShot());
            }
            else
            {
                _AS.pitch = 1;
                _AS.PlayOneShot(_Sounds[0]);
            }
        }

        if (Input.GetButton("Reload") && Time.timeScale != 0)
        {
            _AS.pitch = 1;
            if (_AS.isPlaying == _Sounds[1])
            {
                _AS.Stop();
            }
            _AS.PlayOneShot(_Sounds[1]);

            _Reload.StartReload(_ReloadTime, _Ammo);
        }

        if (Input.GetButtonDown("Dash") && Time.timeScale != 0)
        {
            if (_CanDash)
            {
                Debug.Log("Dashing");
                StartCoroutine(Dash());
            }
        }
    }