コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (playAnimation)
        {
            if (Time.time > setAnimationDelay)
            {
                if (muzzleIncrement < muzzleAnimation.shootRight.Count)
                {
                    spriteRenderer.sprite = muzzleAnimation.shootRight[muzzleIncrement];
                    muzzleIncrement++;
                    setAnimationDelay = Time.time + animationDelay;
                }
                else
                {
                    playAnimation         = false;
                    muzzleIncrement       = 0;
                    spriteRenderer.sprite = null;
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (equip.GetWeapon().ammo > 0)
            {
                if (gameManager.gameState == 0)
                {
                    if (Time.time > setDelay)
                    {
                        playAnimation = true;

                        if (!audioSource.isPlaying)
                        {
                            audioSource.Play();
                        }

                        Instantiate(projectile, exit.position, exit.rotation);

                        setDelay = delay + Time.time;

                        equip.GetWeapon().ammo--;

                        ammoCounter.text = "Ammo: " + equip.GetWeapon().ammo.ToString();
                    }
                }
            }
            else
            {
                audioSource.Stop();
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (playAnimation)
        {
            if (Time.time > setAnimationDelay)
            {
                if (muzzleIncrement < muzzleAnimation.shootRight.Count)
                {
                    spriteRenderer.sprite = muzzleAnimation.shootRight[muzzleIncrement];
                    muzzleIncrement++;
                    setAnimationDelay = Time.time + animationDelay;
                }
                else
                {
                    playAnimation         = false;
                    muzzleIncrement       = 0;
                    spriteRenderer.sprite = null;
                }
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (equip.GetWeapon().ammo > 0)
            {
                if (gameManager.gameState == 0)
                {
                    if (Time.time > setDelay)
                    {
                        playAnimation = true;

                        audioSource.Play();

                        for (int i = 0; i < exit.Count; ++i)
                        {
                            Instantiate(projectile, exit[i].position, exit[i].rotation);

                            if (shootRay)
                            {
                                Debug.DrawLine(exit[i].position, exit[i].forward * maxRayDistance, Color.green);

                                if (Physics.Raycast(exit[i].position, exit[i].forward, out hit, maxRayDistance))
                                {
                                    if (hit.collider.tag[0] == '7')
                                    {
                                        hit.collider.GetComponentInChildren <ParticleSystem>().Play();

                                        hit.collider.GetComponent <Health>().DealDamage(damage);
                                    }
                                }
                            }

                            setDelay = delay + Time.time;
                        }

                        equip.GetWeapon().ammo--;

                        ammoCounter.text = "Ammo: " + equip.GetWeapon().ammo.ToString();
                    }
                }
            }
        }
    }