コード例 #1
0
ファイル: CowSM.cs プロジェクト: Flargy/Portfolio
    /// <summary>
    /// Makes cows emit a sound if they are within range of the player.
    /// </summary>
    /// <param name="eventInfo"> contains infomation brought from <see cref="EventInfo"/></param>
    public void LocateCow(EventInfo eventInfo)
    {
        LocateCowEventInfo locateCowInfo = (LocateCowEventInfo)eventInfo;
        float distance = Vector3.Distance(locateCowInfo.playerPosition, transform.position);

        if (distance < callingRange * 2 && distance > callingRange / 2f)
        {
            if (!audioSource.isPlaying)
            {
                //audioSource.volume = distance ;
                audioSource.pitch = Random.Range(0.8f, 1.5f);
                audioSource.loop  = false;
                audioSource.clip  = mooNoise;
                audioSource.Play();
            }
            //make sound
        }
    }
コード例 #2
0
    /// <summary>
    /// Uses different runes depending on the <see cref="CurrentRune"/> value. And enables the selection of rune.
    /// </summary>
    private void RuneKeys()
    {
        if (Input.GetButtonDown("Rune activation key") || (Input.GetAxisRaw("Rune activation axis") > 0 && XboxInputLeftTriggerNotOnCooldown == true))
        {
            XboxInputLeftTriggerNotOnCooldown = false;
            owner.StartCoroutine(owner.XboxCooldown());
            if (CurrentRune != null && CurrentRune.ReadyToUse() && !Source.isPlaying)
            {
                CurrentRune.Used();
                switch (CurrentRune.GetRuneValue())
                {
                case 1:
                    AudioClip clip = StunGiantSound;
                    Source.PlayOneShot(clip);
                    StunGiantEventInfo sgei = new StunGiantEventInfo {
                        playerPosition = Position.position, stunDistance = StunRange
                    };
                    EventHandeler.Current.FireEvent(EventHandeler.EVENT_TYPE.StunGiant, sgei);
                    MadeANoise(clip.length);
                    break;

                case 2:
                    CalmCowEvent cce = new CalmCowEvent {
                        playerPosition = Position.position
                    };
                    EventHandeler.Current.FireEvent(EventHandeler.EVENT_TYPE.CalmCow, cce);
                    MadeANoise(1);
                    break;

                case 3:
                    LocateCowEventInfo lcei = new LocateCowEventInfo {
                        playerPosition = Position.position
                    };
                    EventHandeler.Current.FireEvent(EventHandeler.EVENT_TYPE.LocateCow, lcei);
                    MadeANoise(1);
                    break;

                default:
                    break;
                }
            }
        }

        if (Input.GetButton("Change rune key") || (Input.GetAxisRaw("Change rune axis") < 0 && XboxInputDownNotOnCooldown == true))
        {
            if (CurrentRune != null)
            {
                XboxInputDownNotOnCooldown = false;
                owner.StartCoroutine(owner.XboxCooldown());
                int temp = CurrentRune.Index;
                temp++;
                if (temp >= RuneNumber)
                {
                    temp = 0;
                }
                CurrentRune = Runes[temp];
                Debug.Log("Sending change rune event with value " + CurrentRune.GetRuneValue());
                ChangeRuneEventInfo crei = new ChangeRuneEventInfo {
                    newRune = CurrentRune
                };
                EventHandeler.Current.FireEvent(EventHandeler.EVENT_TYPE.ChangeRune, crei);
            }
        }
    }