Пример #1
0
    void SpawnEnemy(GameObject _enemy)
    {
        Transform _sp = spawnPoints [Random.Range(0, spawnPoints.Length)];

        GameObject don = Instantiate(_enemy, (Random.insideUnitSphere * 8) + _sp.position, _sp.rotation);

        audio = don.GetComponent <AudioSource> ();

        DonaldBehaviour getAudio     = don.GetComponent <DonaldBehaviour> ();
        AudioClip       randomSounds = getAudio.donaldSounds [0];

        audio.PlayOneShot(randomSounds);
        don.transform.LookAt(center);
    }
Пример #2
0
    //function for firing lazer using raycast hit
    private void Fire()
    {
        Transform cam = Camera.main.transform;

        //rate of fire
        mNextFire = Time.time + mFireRate;

        //the origin of the ray coming out of the camera
        Vector3 rayOrigin = cam.position;

        mLaserLine.SetPosition(0, transform.up * -5f);

        RaycastHit hit;

        //if statement to check if the raycast comes into contact with a collider
        if (Physics.Raycast(rayOrigin, cam.forward, out hit, mFireRange))
        {
            //
            mLaserLine.SetPosition(1, hit.point);

            DonaldBehaviour behaviourScript = hit.collider.GetComponent <DonaldBehaviour> ();
            Debug.Log(hit.collider.transform.position);

            if (behaviourScript != null)
            {
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * mHitForce);

                    //destroys game object as well as instantiating the explosion effect
                    Destroy(Instantiate(deathEffect.gameObject, hit.collider.transform.position, Quaternion.FromToRotation(cam.forward, hit.collider.transform.localPosition)) as GameObject, deathEffect.startLifetime);
                    behaviourScript.Hit(mLaserDamage);
                    //decreases the level of radaiation
                    scoreManager.decreaseCounter();
                    //play the hit sound effect
                    source.PlayOneShot(hitSound);
                }
            }
        }
        else
        {
            mLaserLine.SetPosition(1, cam.forward * mFireRange);
        }

        StartCoroutine(LaserFx());
        source.PlayOneShot(shootSound, 1f);
    }