コード例 #1
0
ファイル: SoundManager.cs プロジェクト: igorawratu/smcd
    public void playTemporarySound(AudioClip clip, float volume, Vector3 position)
    {
        GameObject tempS = (GameObject)Instantiate(tempSound);

        tempS.transform.position = position;
        TemporarySound script = tempS.GetComponent <TemporarySound>();

        script.play(clip, volume);
    }
コード例 #2
0
    /////////////////////////////////////////////////////////////////////////////

    //
    //Properties
    //

    /////////////////////////////////////////////////////////////////////////////

    //
    //Initializers
    //

    /////////////////////////////////////////////////////////////////////////////

    //
    //Methods
    //

    public static void CreateSound(AudioClip clip)
    {
        GameObject  tempGameObject = Instantiate(GetPrefab(), Vector3.zero, Quaternion.identity);
        AudioSource audio          = tempGameObject.GetComponent <AudioSource>();

        audio.clip   = clip;
        audio.volume = GameData.Singleton.GameOptionData.masterVolume;
        TemporarySound tempSound = tempGameObject.GetComponent <TemporarySound>();

        tempSound.StartCoroutine(tempSound.PlaySound(audio));
    }
コード例 #3
0
 public void PlayKilled()
 {
     TemporarySound.CreateSound(killedSound);
 }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.LoadLevel("TitleScreen");
        }

        if (CurrentPlayerKeys.Instance.colourNumbers.Count > 0)
        {
            for (int i = 0; i < keyCodes.Length; i++)
            {
                if (Input.GetKey(keyCodes[i]) &&
                    !CurrentPlayerKeys.Instance.playerExists(MenuScript.keyCodes[i]))
                {
                    float temp = 0;
                    if (keysPressed.TryGetValue(keyCodes[i], out temp))
                    {
                        keysPressed[keyCodes[i]] += Time.deltaTime;
                        if (keysPressed[keyCodes[i]] >= timeToHold)
                        {
                            //Spawn stuff here
                            GameObject canvas = GameObject.Find("Canvas");
                            float      xSpawn = Random.Range(45, 100);
                            initialSpawn += xSpawn;

                            GameObject player = (GameObject)Instantiate(playerPrefab);

                            JoinPlayerJump jpj = player.GetComponent <JoinPlayerJump>();
                            jpj.setKey(keyCodes[i]);

                            //Assign player color
                            int index       = Random.Range(0, CurrentPlayerKeys.Instance.colourNumbers.Count);
                            int colourIndex = CurrentPlayerKeys.Instance.colourNumbers[index];
                            CurrentPlayerKeys.Instance.colourNumbers.RemoveAt(index);
                            CurrentPlayerKeys.Instance.players.Add(new KeyValuePair <KeyCode, Color>(keyCodes[i], CurrentPlayerKeys.Instance.possibleColors[colourIndex]));



                            Transform spacer = player.GetComponentInChildren <Transform>();
                            spacer.GetComponentInChildren <SpriteRenderer>().color = CurrentPlayerKeys.Instance.possibleColors[colourIndex];
                            Transform spawnEffect = spacer.GetComponentInChildren <Transform>();
                            spawnEffect.GetComponentsInChildren <SpriteRenderer>()[1].color = CurrentPlayerKeys.Instance.possibleColors[colourIndex];
                            //Convert position
                            Vector3 xPt    = new Vector3(initialSpawn, 0, 0);
                            Vector3 newXPt = Camera.main.ScreenToWorldPoint(xPt);
                            player.transform.position = new Vector3(newXPt.x, 1, 0);

                            //GameObject spacerObject = player.transform.FindChild("spacer").gameObject;
                            GameObject keyText = player.transform.FindChild("KeyText").gameObject;

                            TextMesh tm = keyText.GetComponent <TextMesh>();
                            tm.text = keyCodes[i].ToString();

                            tm.color = CurrentPlayerKeys.Instance.possibleColors[colourIndex];

                            if (tm.text.Contains("Arrow"))
                            {
                                tm.text = tm.text.Substring(0, tm.text.Length - 5);
                            }


                            keysPressed[keyCodes[i]] = -1000;
                        }
                    }
                    else
                    {
                        keysPressed.Add(keyCodes[i], 0);
                        GameObject     tempSound = (GameObject)Instantiate(SoundManager.instance.tempSound);
                        TemporarySound ts        = tempSound.GetComponent <TemporarySound>();
                        int            rnd       = Random.Range(0, SoundManager.instance.introSpawnSounds.Count);
                        ts.play(SoundManager.instance.introSpawnSounds[rnd],
                                SoundManager.instance.introSpawnVolume);
                        keysSound.Add(keyCodes[i], ts);
                    }
                }
                if (Input.GetKeyUp(keyCodes[i]) &&
                    !CurrentPlayerKeys.Instance.playerExists(MenuScript.keyCodes[i]))
                {
                    float temp = -1000;
                    if (keysPressed.TryGetValue(keyCodes[i], out temp))
                    {
                        if (temp < timeToHold && temp > -900)
                        {
                            keysPressed.Remove(keyCodes[i]);

                            TemporarySound ts      = null;
                            bool           success = keysSound.TryGetValue(keyCodes[i], out ts);
                            if (success)
                            {
                                ts.stop();
                                keysSound.Remove(keyCodes[i]);
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #5
0
ファイル: PlayerSpawner.cs プロジェクト: igorawratu/smcd
    // Update is called once per frame
    void Update()
    {
        float realDeltaTime = Time.realtimeSinceStartup - lastFrameTime;

        lastFrameTime = Time.realtimeSinceStartup;
        //Debug.Log(realDeltaTime);
        //Debug.Log(Time.timeSinceLevelLoad);
        //Debug.Log(Time.time);
        //Debug.Log(Time.realtimeSinceStartup);

        if (CurrentPlayerKeys.Instance.colourNumbers.Count > 0)
        {
            for (int i = 0; i < MenuScript.keyCodes.Length; i++)
            {
                if (Input.GetKey(MenuScript.keyCodes[i]) &&
                    !CurrentPlayerKeys.Instance.playerExists(MenuScript.keyCodes[i]))
                {
                    float temp = 0;
                    if (enteringPlayers.TryGetValue(MenuScript.keyCodes[i], out temp))
                    {
                        //Debug.Log(enteringPlayers[MenuScript.keyCodes[i]]);
                        //Debug.Log(Time.deltaTime);
                        //enteringPlayers[MenuScript.keyCodes[i]] += Time.deltaTime;
                        enteringPlayers[MenuScript.keyCodes[i]] += realDeltaTime;

                        if (enteringPlayers[MenuScript.keyCodes[i]] >= timeToHold)
                        {
                            Debug.Log("Adding player " + MenuScript.keyCodes[i].ToString());
                            //Spawn stuff here
                            GameObject player = (GameObject)Instantiate(playerPrefab);
                            player.name = MenuScript.keyCodes[i].ToString();
                            player.GetComponent <PlayerMovement>().setJumpKey(MenuScript.keyCodes[i]);
                            //Random player's spawn position near the middle
                            Vector3 screenMid = new Vector3(0.5f, 0, 0);
                            startPoint = Camera.main.ViewportToWorldPoint(screenMid).x;
                            offset     = Random.Range(-1, 1);
                            player.transform.position = new Vector3(startPoint + offset, 0.59f, 0);
                            Debug.Log("Added player " + player.name);
                            Debug.Log(player.transform.position);

                            GameObject    wc       = GameObject.Find("WinnerChecker");
                            WinnerChecker wcscript = wc.GetComponent <WinnerChecker>();
                            wcscript.addPlayer(player.name);

                            //Assign player color
                            int index       = Random.Range(0, CurrentPlayerKeys.Instance.colourNumbers.Count);
                            int colourIndex = CurrentPlayerKeys.Instance.colourNumbers[index];
                            CurrentPlayerKeys.Instance.colourNumbers.RemoveAt(index);

                            CurrentPlayerKeys.Instance.players.Add(new KeyValuePair <KeyCode, Color>(MenuScript.keyCodes[i],
                                                                                                     CurrentPlayerKeys.Instance.possibleColors[colourIndex]));

                            player.GetComponent <PlayerMovement>().playerColour = CurrentPlayerKeys.Instance.possibleColors[colourIndex];

                            enteringPlayers[MenuScript.keyCodes[i]] = -1000;
                        }
                    }
                    else
                    {
                        enteringPlayers.Add(MenuScript.keyCodes[i], 0);

                        GameObject     tempSound = (GameObject)Instantiate(SoundManager.instance.tempSound);
                        TemporarySound ts        = tempSound.GetComponent <TemporarySound>();
                        int            rnd       = Random.Range(0, SoundManager.instance.introSpawnSounds.Count);
                        ts.play(SoundManager.instance.introSpawnSounds[rnd],
                                SoundManager.instance.introSpawnVolume);
                        keysSound.Add(MenuScript.keyCodes[i], ts);
                    }
                }

                if (Input.GetKeyUp(MenuScript.keyCodes[i]) &&
                    !CurrentPlayerKeys.Instance.playerExists(MenuScript.keyCodes[i]))
                {
                    float temp = -1000;
                    if (enteringPlayers.TryGetValue(MenuScript.keyCodes[i], out temp))
                    {
                        if (temp < timeToHold && temp > -900)
                        {
                            enteringPlayers.Remove(MenuScript.keyCodes[i]);

                            TemporarySound ts      = null;
                            bool           success = keysSound.TryGetValue(MenuScript.keyCodes[i], out ts);
                            if (success)
                            {
                                ts.stop();
                                keysSound.Remove(MenuScript.keyCodes[i]);
                            }
                        }
                    }
                }
            }
        }
    }