Play() public static method

public static Play ( AudioSource audioSource, AudioClip audioClip ) : void
audioSource AudioSource
audioClip AudioClip
return void
Example #1
0
    void Start()
    {
        navigator = Navigator.instance;
        sfx = AudioManager.instance;

        sfx.Play("Audio/Bgm/Music/Alone", 0.5f, 1f, true);
    }
    private void Move()
    {
        transform.Rotate(Vector3.up * mouseX);
        playerCamera.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

        if (horDirection != 0 || verDirection != 0)
        {
            if (currentStepTimer > 0)
            {
                currentStepTimer -= Time.deltaTime;
                goto Movement;
            }

            currentStepTimer = stepTimer;
            audioManager?.Play("Step", 2);
        }
        else
        {
            currentStepTimer = 0;
        }

Movement:

        rb.MovePosition(transform.position +
                        (transform.forward * verDirection * movementSpeed * Time.fixedDeltaTime) +
                        (transform.right * horDirection * movementSpeed * Time.fixedDeltaTime));
    }
Example #3
0
 void Awake()
 {
     sfx = AudioManager.instance;
     navigator = Navigator.instance;
     sfx.Play("Audio/Bgm/Scenes/GameOver", 0, 1f, true);
     sfx.Fade("Audio/Bgm/Scenes/GameOver", 0.25f, 0.5f);
 }
    private void playSoundAndUpdateStateForSound()
    {
        depressionSoundPlayed = lerp < 0.1 && depressionSoundPlayed ? false : true;
        releaseSoundPlayed    = lerp > 0.9 && releaseSoundPlayed ? false : true;

        bool ventilatorIsBeingDepressed = lerp - previousLerp < 0 ? true : false;
        bool ventilatorIsBeingReleased  = lerp - previousLerp > 0 ? true : false;

        if (ventilatorIsBeingDepressed && !depressionSoundPlayed)
        {
            audioManager?.Play("VentilatorPress");
            depressionSoundPlayed = true;
        }

        if (ventilatorIsBeingReleased && !releaseSoundPlayed)
        {
            audioManager?.Play("VentilatorRelease");
            releaseSoundPlayed = true;
        }
    }
Example #5
0
    void TakeDamage(Vector2 sourcePosition, int receivedDamage = 1)
    {
        _audioManager?.Play("Damage");

        if (!isInvincible)
        {
            Health      -= receivedDamage;
            isInvincible = true;
            StartCoroutine(InvencibilityBlink());
            KnockBack(sourcePosition);
        }

        if (Health < 0)
        {
            Health = 0;
        }

        if (Health == 0)
        {
            FinishGame(Gamestate.PhoneOwn);
        }
    }
 public void GoBack()
 {
     AudioManager.Play(AudioClipName.MenuButtonClick);
     MenuManager.GoToMenu(MenuName.Main);
 }
 public void HandleHardButtonOnClickEvent()
 {
     AudioManager.Play(AudioClipName.MenuButtonClick);
     unityEvents[EventName.GameStartedEvent].Invoke((int)Difficulty.Hard, GameType.OnePlayer);
 }
Example #8
0
 private void Start()
 {
     audio.Play(title);
 }
Example #9
0
 void BoomAction()
 {
     _audio.Play("BoomBomb");
     BoomWave.enabled = true;
 }
Example #10
0
 /// <summary>
 /// Regresa al menú principal
 /// </summary>
 public void Back()
 {
     AudioManager.Play(AudioClipName.Click);
     PlayerPrefs.Save(); //OJO
     MenuManager.GoToMenu(MenuName.Main);
 }
Example #11
0
 protected override void OnCollisionEnter2D(Collision2D collision)
 {
     AudioManager.Play(AudioClipName.BonusBlock);
     base.OnCollisionEnter2D(collision);
 }
Example #12
0
 void Open()
 {
     isOpen = true;
     am.Play("doorOpen");
     GetComponent <SpriteRenderer> ().sprite = openSprite;
 }
Example #13
0
        public void enterState(Interactable item)
        {
            // Remove Children GameObjects to Remove Assocaited Prefabs
            foreach (Transform child in item.transform)
            {
                if (child.tag != "Static")
                {
                    child.gameObject.SetActive(false);
                    GameObject.Destroy(child.gameObject);
                }
            }

            // Update with Prefab
            if (prefab != null)
            {
                GameObject _prefab = GameObject.Instantiate(prefab, item.transform);
                _prefab.transform.position += positionOffset;

                if (item.GetComponent <MeshFilter>() != null)
                {
                    item.GetComponent <MeshFilter>().sharedMesh = null;
                }
            }
            else
            {
                item.transform.position += positionOffset;
            }

            // Update Mesh
            if (mesh != null)
            {
                item.GetComponent <MeshFilter>().sharedMesh = mesh;
            }

            // Update Material and Material Index
            if (material != null)
            {
                Material[] materials = item.GetComponent <Renderer>().materials;
                materials[materialIndex] = material;
                item.GetComponent <Renderer>().materials = materials;
            }

            // Set UVOffset for current material/material index
            if (item.GetComponent <Renderer>() != null)
            {
                item.GetComponent <Renderer>().materials[materialIndex].SetTextureOffset("_MainTex", uvOffset);
            }

            // Update animation controller
            if (animatorController != null)
            {
                item.GetComponentInChildren <Animator>().runtimeAnimatorController = animatorController;
            }

            // Play sound effect clip
            if (soundEffectName != "")
            {
                AudioManager.Play(soundEffectName);
            }

            // Create and Play Particle Effects
            if (particleEffectName != "")
            {
                EffectsManager.PlayEffect(particleEffectName, item.transform);
            }
            else if (particleEffect != null)
            {
                EffectsManager.PlayEffect(particleEffect, item.transform);
            }
            else if (item.stateData.effect != null)
            {
                EffectsManager.PlayEffect(item.stateData.effect, item.transform);
            }
        }
Example #14
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     Destroy(collision.gameObject);
     AudioManager.Play(AudioClipName.Explosion);
 }
Example #15
0
    void Shoot()
    {
        RaycastHit hit;

        if (DamageType == AgentStats.DamageType.pistol)
        {
            if (pistolAnimations.shooting || pistolAnimations.reloading)
            {
                Debug.Log("Cannot shoot while shooting or reloading");
                return;
            }

            Collider[] hitColliders = Physics.OverlapSphere(transform.position, pistolNoiseRange);

            foreach (Collider col in hitColliders)
            {
                ZombieController enemy = col.GetComponent <ZombieController>();
                if (enemy != null)
                {
                    enemy.Alert(this.gameObject);
                }
            }

            if (currentPistolMagazine <= 0)
            {
                return;
            }

            audio.Play("PistolShot");
            currentPistolMagazine--;
            pistolAnimations.anim.SetInteger("RoundsLoaded", currentPistolMagazine);
            pistolAnimations.anim.SetTrigger("Fire");


            stats.ammoCounter?.SetAmmoCounter(currentPistolMagazine, stats.pistolAmmo);


            if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, pistolRange, layerMask))
            {
                AgentStats enemyStat = hit.transform.GetComponentInParent <AgentStats>();
                if (enemyStat != null)
                {
                    enemyStat.ApplyDamage(stats.GetDamageValue(DamageType), DamageType, stats);
                }

                GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impactGO, 2.5f);
            }
        }
        else
        if (DamageType == AgentStats.DamageType.shotgun)
        {
            if (shotgunAnimations.shooting || shotgunAnimations.reloading)
            {
                Debug.Log("Cannot shoot while shooting or reloading");
                return;
            }

            /////////////////////////////Alert Nearby agents////////////////////////////////////////
            Collider[] hitColliders = Physics.OverlapSphere(transform.position, shotgunNoiseRange);

            foreach (Collider col in hitColliders)
            {
                ZombieController enemy = col.GetComponent <ZombieController>();
                if (enemy != null)
                {
                    enemy.Alert(this.gameObject);
                }
            }
            ////////////////////////////////////////////////////////////////////////////////////////

            if (currentShotgunMagazine <= 0)
            {
                return;
            }

            //Start shooting animation
            shotgunAnimations.anim.SetInteger("RoundsLoaded", currentShotgunMagazine);
            shotgunAnimations.anim.SetTrigger("Fire");
            audio.Play("ShotgunShot");
            currentShotgunMagazine--;
            stats.ammoCounter?.SetAmmoCounter(currentShotgunMagazine, stats.shotgunAmmo);
            RaycastHit shotHit;

            for (int i = 0; i < shotgunPellets; i++)
            {
                var v3Offset = transform.up * Random.Range(0.0f, shotgunVariance);
                v3Offset = Quaternion.AngleAxis(Random.Range(0.0f, 360.0f), transform.forward) * v3Offset;
                Vector3 v3Hit = fpsCam.transform.forward * shotgunRange + v3Offset;


                if (Physics.Raycast(fpsCam.transform.position, v3Hit, out shotHit, shotgunRange, layerMask))
                {
                    AgentStats enemyStat = shotHit.transform.GetComponentInParent <AgentStats>();
                    if (enemyStat != null)
                    {
                        enemyStat.ApplyDamage(stats.GetDamageValue(DamageType), DamageType, stats);
                    }
                }

                GameObject impactGO = Instantiate(impactEffect, shotHit.point, Quaternion.LookRotation(shotHit.normal));
                Destroy(impactGO, 2.5f);
            }
        }
        else
        {
            return;
        }
    }
Example #16
0
    void Move()
    {
        isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, groundLayer);
        if (isGrounded == true)
        {
            rb.gravityScale = normalGravity;
            animator.SetFloat("yVelocity", 0);
        }
        else
        {
            coyoteTimeTimer = coyoteTime;
            animator.SetFloat("yVelocity", rb.velocity.y);
        }

        // Rotate player and play right animation
        if (hAxis != 0)
        {
            transform.eulerAngles = (hAxis > 0) ? new Vector3(0, 180, 0) : new Vector3(0, 0, 0);
            animator.SetBool("moving", (!isGrounded) ? false : true);
        }
        else
        {
            animator.SetBool("moving", false);
        }

        // If player is on the ground and they jump
        if (Math.Abs(rb.velocity.y) <= 0.1f && (isGrounded == true || coyoteTimeTimer > 0) && (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)))
        {
            audioManager.Play("Jump");
            GameObject impactInstance = Instantiate(impactParticlePrefab, feetPos.position, Quaternion.identity);
            impactInstance.transform.Rotate(10f, 0, 0, Space.Self);
            isJumping       = true;
            jumpTimeCounter = jumpTime;
            rb.velocity     = Vector2.up * jumpForce;
            coyoteTimeTimer = 0;
        }

        // While player is in middle of jump
        if (isJumping == true)
        {
            if (jumpTimeCounter > 0)
            {
                rb.AddForce(new Vector2(0, jumpForce * 0.025f), ForceMode2D.Impulse);
                jumpTimeCounter -= Time.deltaTime;
            }
            else
            {
                isJumping       = false;
                rb.gravityScale = fallingGravity;
            }
        }

        // After player hits jump
        if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow))
        {
            isJumping       = false;
            rb.gravityScale = fallingGravity;
        }
        if (Input.GetMouseButtonDown(0) && boneCdTimer <= 0 && bones > 0 && Time.timeScale == 1)
        {
            mousePos  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            direction = new Vector2(mousePos.x - transform.position.x, mousePos.y - transform.position.y);
            direction.Normalize();
            transform.Find("BoneSource").transform.up = direction;
            bonesThrownCount++;
            audioManager.Play("ThrowBone");
            GameObject boneInstance = Instantiate(bonePrefab, boneSourcePos.position, Quaternion.identity);
            Physics2D.IgnoreCollision(col, boneInstance.GetComponent <BoneControl>().GetCollider2D(), true);
            boneInstance.GetComponent <BoneControl>().initialVelocity(direction);
            boneCdTimer = boneCd;
            bones--;
        }
        else if (Input.GetMouseButtonDown(0) && boneCdTimer <= 0 && bones == 0 && Time.timeScale == 1)
        {
            audioManager.Play("OutofBones");
            boneCdTimer = boneCd;
            GameObject.Find("Ui").GetComponent <hudControl>().outOfBones();
        }
        boneCdTimer     -= Time.deltaTime;
        coyoteTimeTimer -= Time.deltaTime;
    }
 public void Hide()
 {
     _showing = false;
     _window.SetActive(false);
     AudioManager.Play(_showHideSound);
 }
Example #18
0
 public void PlayClick()
 {
     AudioManager.Play(AudioClipName.Click);
 }
Example #19
0
    IEnumerator MoveCoroutine()
    {
        while (Input.GetAxisRaw("Vertical") != 0 || Input.GetAxisRaw("Horizontal") != 0)
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                applyRunSpeed = runSpeed;
                applyRunFlag  = true;
            }
            else
            {
                applyRunSpeed = 0;
                applyRunFlag  = false;
            }

            vector.Set(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), transform.position.z);
            // z 축은 변하지 않는 값

            if (vector.x != 0)
            {
                vector.y = 0;
            }

            if (vector.y != 0)
            {
                vector.x = 0;
            }
            animator.SetFloat("DirX", vector.x); // vector.x 의 값을 DirX로 전달.
            animator.SetFloat("DirY", vector.y);

            bool checkCollisionFlag = base.CheckCollision();
            if (checkCollisionFlag) // 앞에 뭔가 있다! -> true, 가지 않겠다! walking false
            {
                break;
            }

            animator.SetBool("Walking", true);

            int temp = Random.Range(1, 4);
            switch (temp)
            {
            case 1:
                theAudio.Play(walkSound_1);
                break;

            case 2:
                theAudio.Play(walkSound_2);
                break;

            case 3:
                theAudio.Play(walkSound_3);
                break;

            case 4:
                theAudio.Play(walkSound_4);
                break;
            }


            while (currentWalkCount < walkCount)
            {
                if (vector.x != 0)
                {
                    transform.Translate(vector.x * (speed + applyRunSpeed), 0, 0);
                }
                else if (vector.y != 0)
                {
                    transform.Translate(0, vector.y * (speed + applyRunSpeed), 0);
                    // Translate 함수는 현재 있는 값에서 주어진 값 만큼 더해주는 것
                }
                if (applyRunFlag)
                {
                    currentWalkCount++;
                }
                currentWalkCount++;
                yield return(new WaitForSeconds(0.01f));
            }
            currentWalkCount = 0;
        }

        animator.SetBool("Walking", false);


        canMove = true;
    }
Example #20
0
    private void Update()
    {
        if (!stopKeyInput)
        {
            if (Input.GetKeyDown(KeyCode.I))
            {
                activated = !activated;
                if (activated)
                {
                    theAudio.Play(open_sound);
                    // theOrder.NotMove();
                    go.SetActive(true);
                    selectedTab   = 0;
                    tabActivated  = true;
                    itemActivated = false;
                    ShowTab();
                    // StartCoroutine(Sele)
                }
                else
                {
                    theAudio.Play(cancel_sound);
                    StopAllCoroutines();
                    go.SetActive(false);
                    tabActivated  = false;
                    itemActivated = false;
                    // theOrder.Move();
                }
            }
        }

        if (activated)
        {
            if (tabActivated)
            {
                if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    if (selectedTab < selectedTabImages.Length - 1)
                    {
                        selectedTab++;
                    }
                    else
                    {
                        selectedTab = 0;
                    }
                    theAudio.Play(key_sound);
                    SelectedTab();
                }
                else if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    if (selectedTab > 0)
                    {
                        selectedTab--;
                    }
                    else
                    {
                        selectedTab = selectedTabImages.Length - 1;
                    }
                    theAudio.Play(key_sound);
                    SelectedTab();
                }
                else if (Input.GetKeyDown(KeyCode.Z))
                {
                    theAudio.Play(enter_sound);
                    Color color = selectedTabImages[selectedTab].GetComponent <Image>().color;
                    color.a = 0.25f;
                    selectedTabImages[selectedTab].GetComponent <Image>().color = color;
                    itemActivated = false;
                    tabActivated  = false;
                    preventExec   = true;
                    ShowItem();
                }
            }
        }
    }
Example #21
0
    IEnumerator MoveCoroutine()
    {
        while ((Input.GetAxisRaw("Vertical") != 0 || Input.GetAxisRaw("Horizontal") != 0) && !notMove && !attacking)
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                applyRunSpeed = runSpeed;
                applyRunFlag  = true;
            }
            else
            {
                applyRunSpeed = 0;
                applyRunFlag  = false;
            }

            vector.Set(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), transform.position.z);

            if (vector.x != 0)
            {
                vector.y = 0;
            }

            animator.SetFloat("DirX", vector.x);
            animator.SetFloat("DirY", vector.y);

            bool checkCollsionFlag = base.CheckCollsion();
            if (checkCollsionFlag)
            {
                break;
            }

            animator.SetBool("Walking", true);

            int temp = Random.Range(1, 4);

            if (temp == 1)
            {
                theAudio.Play(walkSound_1);
            }
            else if (temp == 2)
            {
                theAudio.Play(walkSound_2);
            }
            else if (temp == 3)
            {
                theAudio.Play(walkSound_3);
            }
            else if (temp == 4)
            {
                theAudio.Play(walkSound_4);
            }

            theAudio.SetVolume(walkSound_2, 0.5f);

            while (currentWalkCount < walkCount)
            {
                transform.Translate(vector.x * (speed + applyRunSpeed), vector.y * (speed + applyRunSpeed), 0);
                if (vector.x != 0)
                {
                    transform.Translate(vector.x * (speed + applyRunSpeed), 0, 0);
                }
                else if (vector.y != 0)
                {
                    transform.Translate(0, vector.y * (speed + applyRunSpeed), 0);
                }
                if (applyRunFlag)
                {
                    currentWalkCount++;
                }
                currentWalkCount++;
                yield return(new WaitForSeconds(0.01f));
            }

            currentWalkCount = 0;
        }

        animator.SetBool("Walking", false);
        canMove = true;
    }
Example #22
0
    void Start()
    {
        FindObjectOfType <AudioManager>().deathCount = 0;
        slider.value = AudioListener.volume;
        FindObjectOfType <AudioManager>().setVolume(slider.value);
        aM.Play("MainTheme");

        Cursor.visible = false;
    }
    // Update is called once per frame
    void Update()
    {
        //if(coolDownVariable<=0)
        //{
        //    isSetToFire = true;
        //}
        //else
        //{
        //    coolDownVariable -= Time.deltaTime;
        //}
        if (isActivated)
        {
            if (isSetToFire)
            {
                if (takenControl)
                {
                    if (anticipationVariable <= 0)
                    {
                        //Calculations
                        damageVariable = dmgPerSec * dmgMultiplyer;
                        //Projectile instantiation
                        Debug.Log("Instantiates box");
                        GameObject instantiatedObject = Instantiate(trapBoxPrefab, spawnPoint.position, characterTransform.rotation);
                        instantiatedObject.GetComponent <Rigidbody>().velocity = throwVector;
                        CCAttack_Box boxScript = instantiatedObject.GetComponent <CCAttack_Box>();
                        boxScript.pManager          = attackingPlayer;
                        boxScript.stunTimeVariable  = stunTime;
                        boxScript.dmgPerSecVariable = damageVariable;
                        boxScript.secToDestroy      = projectileLifeTime;
                        boxScript.projectileOwner   = character;
                        //CCstart audio
                        if (audioManager != null)
                        {
                            audioManager.Play("Ranger_CC");
                        }
                        //Reset
                        //isSetToFire = false;
                        isActivated          = false;
                        takenControl         = false;
                        anticipationVariable = anticipationTime;
                        //coolDownVariable = coolDown;
                    }
                    else
                    {
                        anticipationVariable -= Time.deltaTime;
                    }
                }
                else
                {
                    character.GetComponent <PlayerManager>().Immobile(false, anticipationVariable);
                    throwVector = CalcThrowVector(destinationPoint.position, spawnPoint.position, projectileFlyTime);
                    //CCstart audio
                    if (audioManager != null)
                    {
                        audioManager.Play("Character_CCStart");
                    }

                    takenControl = true;
                }
            }
            else
            {
                isActivated = false;
            }
        }

        transform.position    = hand.position;
        transform.eulerAngles = hand.eulerAngles;
    }
Example #24
0
 public void onTutorial()
 {
     audioMan.Play("Menu");
     SceneManager.LoadScene(2);
 }
Example #25
0
 void ResetAndGoToMenu()
 {
     AudioManager.Play("Click");
     GameRecordManager.instance.ResetLifeAndLevel();
     SceneManager.LoadScene("MenuScene");
 }
Example #26
0
 public void Rain()
 {
     theAudio.Play(rainSound);
     rain.Play();
 }
Example #27
0
 // Start is called before the first frame update
 public void BackOnClick()
 {
     AudioManager.Play(AudioClipName.Click);
     Destroy(GameObject.FindGameObjectWithTag("HelpMenuCanvas"));
     MenuManager.GoToMenu(Menu.Main);
 }
Example #28
0
 void LeftStepSound()
 {
     audio.Play("FootStepLeft");
 }
Example #29
0
 public void DeathSound()
 {
     audioManager.Play("EnemyDie");
 }
Example #30
0
    // Update is called once per frame
    void Update()
    {
        grounded = IsGrounded();
        wall     = IsWalled();

        if (nairing && grounded)
        {
            nairing = false;
        }
        if (jabbing && !grounded)
        {
            jabbing = false;
        }

        if (!spawn)
        {
            if (ply.transform.position.x >= 16)
            {
                spawn = true;
                audio.Play("SecondBoss");
                GameObject[] temp = GameObject.FindGameObjectsWithTag("tile_boss");
                for (int i = 0; i < temp.Length; i++)
                {
                    temp[i].GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 1);
                }
                GameObject.Find("bg_1").GetComponent <SpriteRenderer>().enabled = false;
                GameObject.Find("bg_2").GetComponent <SpriteRenderer>().enabled = true;
                GetComponent <SpriteRenderer>().enabled    = true;
                GetComponent <CapsuleCollider2D>().enabled = true;
                GetComponent <BoxCollider2D>().enabled     = true;
                GetComponent <Rigidbody2D>().isKinematic   = false;
                heaalth0.enabled = true;
                health1.enabled  = true;
            }
        }
        else
        {
            if (!phase2 && ((self.health * 1.0) / self.maxHealth) < 0.6f)
            {
                speed      += 2;
                self.attack = Mathf.FloorToInt(self.attack * 1.2f);
                phase2      = true;
            }

            canJump = grounded && !nairing && !jabbing && !jumpCD;

            if (!jabbing)
            {
                if (facing == 1 && wall && ply.transform.position.x - transform.position.x > 0.3f)
                {
                    rb.velocity = new Vector2(0, rb.velocity.y);
                }
                else if (facing == -1 && wall & ply.transform.position.x - transform.position.x < -0.3f)
                {
                    rb.velocity = new Vector2(0, rb.velocity.y);
                }
                else if (ply.transform.position.x - transform.position.x > 0.3f)
                {
                    rb.velocity = new Vector2(speed, rb.velocity.y);
                }
                else if (ply.transform.position.x - transform.position.x < -0.3f)
                {
                    rb.velocity = new Vector2(-speed, rb.velocity.y);
                }
                else
                {
                    rb.velocity = new Vector2(0, rb.velocity.y);
                }

                /*if (ply.transform.position.x - transform.position.x > 0 && Mathf.Abs(transform.position.y - ply.transform.position.y) > 0.3f)
                 * {
                 *  rb.velocity = new Vector2(speed, rb.velocity.y);
                 * }
                 * else if (ply.transform.position.x - transform.position.x < 0 && Mathf.Abs(transform.position.y - ply.transform.position.y) > 0.3f)
                 * {
                 *  rb.velocity = new Vector2(-speed, rb.velocity.y);
                 * }*/
            }
            else
            {
                rb.velocity = Vector2.zero;
            }

            if (wall && grounded && canJump && ((ply.transform.position.x - transform.position.x > 0.3f) || (ply.transform.position.x - transform.position.x < -0.3f)))
            {
                StartCoroutine(Jump(lowJump));
            }
            else if (Mathf.Abs(ply.transform.position.x - transform.position.x) < 0.3f)
            {
                if (ply.transform.position.x - transform.position.x >= 0)
                {
                    facing = 1;
                }
                else
                {
                    facing = -1;
                }

                float yDist = ply.transform.position.y - transform.position.y;
                if (!attNoHB)
                {
                    StartCoroutine(Att(yDist));
                }
            }
        }

        if (rb.velocity.x > 0)
        {
            facing = 1;
        }
        else if (rb.velocity.x < 0)
        {
            facing = -1;
        }

        transform.localScale = new Vector3(facing, 1f, 1f);
        if (bar != null && spawn)
        {
            bar.transform.localScale = new Vector3(facing * 3, 2, 1);
        }

        anim.SetFloat("speedX", Mathf.Abs(rb.velocity.x));
        anim.SetFloat("speedY", rb.velocity.y);
        anim.SetBool("grounded", grounded);
        anim.SetBool("nairing", nairing);
        anim.SetBool("jabbing", jabbing);
    }
    // Update is called once per frame
    void Update()
    {
        //Debug.DrawRay(agentCollider.bounds.center, Vector2.right, Color.red);
        //Get TerrainMap
        if (!getTerrain)
        {
            terrainMap = GameObject.FindGameObjectWithTag("TerrainMap").GetComponent <GridSettings>().GetGrid();
            getTerrain = true;
        }

        if (currentState == AiStates.Patrol)
        {
            path.Clear();
            AiAnimations.Walk(agentAnimator);
            if (AiMaths.SightSphere(agentCollider, agentInfo.sightRange, playerMask))
            {
                currentState = AiStates.Chase;
            }

            else if (AiMaths.raycastSides(agentCollider.GetComponent <Collider2D>(), floorMask, (int)transform.localScale.x, gameObject))
            {
                transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
            }

            GetComponent <Rigidbody2D>().velocity = new Vector2(3 * (int)transform.localScale.x, GetComponent <Rigidbody2D>().velocity.y);
        }
        else if (currentState == AiStates.Chase)
        {
            if (KylesFunctions.IsNextToWall2D(transform.localScale.x, agentCollider, 0.5f, playerMask))
            {
                path.Clear();
                currentState = AiStates.Attack;
            }
            else
            {
                AiAnimations.Walk(agentAnimator);



                if (AiMaths.SightSphere(agentCollider, agentInfo.sightRange, playerMask))
                {
                    Vector2 agentNewHeight = new Vector2(GetComponent <CapsuleCollider2D>().bounds.center.x, GetComponent <CapsuleCollider2D>().bounds.center.y - GetComponent <CapsuleCollider2D>().bounds.extents.y);
                    if (!getPlayerPos)
                    {
                        // KylesFunctions.GetXY(agentNewHeight, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out playerGridPos);
                        KylesFunctions.GetXY(player.transform.position, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out playerGridPos);
                        getPlayerPos = true;
                    }

                    KylesFunctions.GetXY(agentNewHeight, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out agentGridPos);
                    KylesFunctions.GetXY(player.transform.position, terrainMap.GetOriginPos(), terrainMap.GetCellSize(), out newPlayerPos);


                    if (newPlayerPos != playerGridPos)
                    {
                        // playerGridPos = newPlayerPos;
                        getPlayerPos = false;
                        path.Clear();
                        findPath = true;
                    }

                    if (path.Count == 0 && !KylesFunctions.IsNextToWall2D(transform.localScale.x, agentCollider, 0.5f, playerMask))
                    {
                        findPath = true;
                    }

                    if (findPath)
                    {
                        KylesFunctions.AStar(terrainMap, agentGridPos.x, agentGridPos.y, playerGridPos.x, playerGridPos.y, 2, false, ref path);
                        findPath = false;
                    }
                }
                else
                {
                    currentState = AiStates.Patrol;
                }
            }
        }
        else if (currentState == AiStates.Attack)
        {
            timer = Time.deltaTime + timer;
            if (!AiMaths.SightSphere(agentCollider, 1.0f, playerMask))
            {
                currentState = AiStates.Chase;
                timer        = 3;
            }

            else if (!isAttacking && timer > 3.0f)
            {
                isAttacking = true;
                audioManager.Play("MantisAttack", gameObject);

                StartCoroutine(DoAttack());
                timer = 0;
            }
            else
            {
                AiAnimations.Walk(agentAnimator);
            }
        }
        else if (currentState == AiStates.AmountOfStates)
        {
        }
    }
Example #32
0
 void JumpAnimation()
 {
     CurrentAnimation.SetInteger("AnimationPlayer", 3);
     audioManager.Play("PlayerJump", gameObject);
 }
Example #33
0
    void Awake()
    {
        // Initialize singletons
        FpsCounter fps = FpsCounter.instance;
        fps.enabled = true;

        navigator = Navigator.instance;

        sfx = AudioManager.instance;
        sfx.Play("Audio/Bgm/Music/Alone", 0.5f, 1f, true);
        sfx.Play("Audio/Bgm/Ambient/BonusWind", 1f, 1f, true);
    }