Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (Time.timeScale == 0)
        {
            return;
        }

        if (Input.GetButtonDown("Fire1"))
        {
            AudioSource.PlayClipAtPoint(shootSounds[0], transform.position, .25f);

            Vector3    dir = Camera.main.transform.forward;
            RaycastHit hitInfo;

            //int layerMask = (1 << 11) | Physics.kDefaultRaycastLayers;

            if (Physics.Raycast(Camera.main.transform.position, dir, out hitInfo, range, laserMask.value))
            {
                Transform victim = hitInfo.collider.transform;

                Destroyable dest = victim.GetComponent <Destroyable>();
                while (dest == null && victim.parent != null)
                {
                    victim = victim.parent;
                    dest   = victim.GetComponent <Destroyable>();
                }

                if (dest != null)
                {
                    dest.DestroyMe();
                    Score.AddMult();
                }

                Missile missile = victim.GetComponent <Missile>();
                if (missile != null)
                {
                    missile.Explode();
                    Score.AddPoints(10000);
                }

                SpawnLaser(hitInfo.point);
                Instantiate(laserHitPrefab, hitInfo.point, Quaternion.identity);
            }
            else
            {
                SpawnLaser(Camera.main.transform.position + Camera.main.transform.forward * range);
            }
        }
    }