示例#1
0
    void Update()
    {
        if (startTime != -1)
        {
            if (Time.time - startTime >= abilityTime)
            {
                startTime = -1;
                particles.Stop();
                lastActiveTime = Time.time;
                animator.SetBool("IsSpraying", false);
            }
        }

        if (Input.GetButtonDown(button) && Time.time - lastActiveTime >= rechargeTime && lotionManager.UseLotion(lotionCost))
        {
            Quaternion rotation = Quaternion.Euler(0, player.left ? 180 : 0, 0);
            particles.transform.rotation = rotation;

            lastActiveTime = Time.time;
            startTime      = Time.time;

            particles.Play();

            var velocity = rotation * new Vector3(projectileSpeed, 0, 0);

            var instance = Instantiate(projectile);
            instance.GetComponent <AbilityProjectile>().damage = damage;
            Rigidbody2D body = instance.GetComponent <Rigidbody2D>();
            body.position = transform.position + new Vector3(0, projectileYOffset, 0);
            body.velocity = velocity;

            AudioSource audioSource = GetComponent <AudioSource>();

            if (audioSource == null)
            {
                audioSource = this.gameObject.AddComponent <AudioSource>();
            }

            AudioManager.instance.PlayAudio(audioSource, SFX.Squirt);

            animator.SetBool("IsSpraying", true);
        }
    }