コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (allowSpawning)
        {
            timeSinceLastSpawn += Time.deltaTime;

            //If we are over spawn time then spawn an object
            if (timeSinceLastSpawn >= nextSpawnTime)
            {
                SpawnObject();
                ResetSpawnTimers();

                //Play spawn Sound
                if (spawnAudioSource && spawnSound)
                {
                    spawnAudioSource.PlaySFX(spawnSound);
                }

                if (increaseScore)
                {
                    //Increase Game Score when we spawn a new object
                    ScoreKeeper.CurrentScore++;
                }
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (shootingEnabled)
        {
            //Check for shot touch
            if (TouchInput.TouchIsValid(TouchDefines.shotTouchID))
            {
                //If there has been enough time since the last shot then create a new bullet
                if (shotTimer < 0)
                {
                    //Spawn bullets at all of the bullet spawn points
                    for (int i = 0; i < bulletSpawns.Length; i++)
                    {
                        //Create Bullet, set it's postion and direction
                        ShipBullet createdBullet = Instantiate(bulletPrefab).GetComponent <ShipBullet>();
                        createdBullet.transform.position = transform.TransformPoint(bulletSpawns[i]);
                        createdBullet.transform.rotation = gameObject.transform.rotation;
                        createdBullet.BulletCreator      = gameObject;
                    }

                    //Play Shooting Sound
                    if (shootingAudioSource && shootingSound)
                    {
                        shootingAudioSource.PlaySFX(shootingSound);
                    }

                    //Reset Shot Timer
                    shotTimer = shotSpacing;
                }
            }

            //Decrease shot time
            shotTimer -= Time.deltaTime;
        }
    }
コード例 #3
0
 private void Start()
 {
     //Play Lose Sound when the player fails
     if (loseAudioSource && loseSound)
     {
         loseAudioSource.PlaySFX(loseSound);
     }
 }
コード例 #4
0
    private void Start()
    {
        //Update UI Elements
        UpdateLatestScoreText();

        //Play Audio
        loseAudioSource.PlaySFX(loseSound);
    }
コード例 #5
0
 private void Start()
 {
     //Play Lose Sound when the player fails
     if (audioSource && sound)
     {
         audioSource.PlaySFX(sound);
     }
 }
コード例 #6
0
    private void Start()
    {
        //Update UI Elements
        UpdateLatestScoreText();

        //Play Win Sound
        if (winAudioSource && winSound)
        {
            winAudioSource.PlaySFX(winSound);
        }
    }
コード例 #7
0
    private void Start()
    {
        //Update UI Elements
        UpdateLatestScoreText();

        //Play Lose Sound when the player fails
        if (loseAudioSource && loseSound)
        {
            loseAudioSource.PlaySFX(loseSound);
        }
    }
コード例 #8
0
    /// <summary>
    /// Register the coin as picked up
    /// </summary>
    public void RegisterPickup()
    {
        //Play sound
        if (soundSource && pickupSound)
        {
            soundSource.PlaySFX(pickupSound);
        }

        //Hide and disable collisions
        pickupModel.SetActive(false);
        GetComponent <Collider>().enabled = false;

        //Destory object after sound has played
        Destroy(gameObject, pickupSound.length);
    }
コード例 #9
0
    /// <summary>
    /// Explode this wall in to sub cubes
    /// </summary>
    public void ExplodeWall()
    {
        if (wallColliders != null)
        {
            //Create cubes within each collider
            foreach (Collider collider in wallColliders)
            {
                //Get the colliders size
                Vector3 colliderSize = collider.bounds.size;

                //Work out the top left of the cube
                Vector3 cubeOrigin = transform.position - (colliderSize / 2);

                for (float x = 0; x < colliderSize.x; x += explosionCubeSize)
                {
                    for (float y = 0; y < colliderSize.y; y += explosionCubeSize)
                    {
                        for (float z = 0; z < colliderSize.z; z += explosionCubeSize)
                        {
                            GameObject piece = CreateExplosionPiece(cubeOrigin + new Vector3(x, y, z), Vector3.one);
                            piece.GetComponent <Rigidbody>().velocity = new Vector3(Random.Range(5, 20), 0, 0);
                            //Set to have the same material as the wall
                            piece.GetComponent <Renderer>().material = gameObject.GetComponent <Renderer>().material;
                        }
                    }
                }

                //Play Explosion Sound
                if (explosionSource && explosionSound)
                {
                    explosionSource.PlaySFX(explosionSound);
                }

                //Destroy Collider and renderer
                GetComponent <Collider>().enabled = false;
                GetComponent <Renderer>().enabled = false;
                //Set to Destroy object after audio has played
                Destroy(gameObject, explosionSound.length);
            }
        }
    }