예제 #1
0
 private Ray[] scatterRays(Vector3 shotPos)
 {
     Ray[] rays = new Ray[5];
     rays[0] = FirstPersonCamera.ScreenPointToRay(new Vector3(shotPos.x, shotPos.y, 0));
     rays[1] = FirstPersonCamera.ScreenPointToRay(new Vector3(shotPos.x - scatterSize, shotPos.y + scatterSize, 0));
     rays[2] = FirstPersonCamera.ScreenPointToRay(new Vector3(shotPos.x + scatterSize, shotPos.y + scatterSize, 0));
     rays[3] = FirstPersonCamera.ScreenPointToRay(new Vector3(shotPos.x + scatterSize, shotPos.y - scatterSize, 0));
     rays[4] = FirstPersonCamera.ScreenPointToRay(new Vector3(shotPos.x - scatterSize, shotPos.y - scatterSize, 0));
     return(rays);
 }
예제 #2
0
    private IEnumerator fireAction()
    {
        // 更新AR環境碰撞體,等待3幀
        SingleObj <DepthMeshColliderCus> .obj.ScanDepthCollider();

        yield return(new WaitForSeconds(0.1f));

        float      timing      = 0;
        Vector2    raycastPose = getSightPosToScreen();
        GameObject hitEnemy    = null;

        muzzleFire.gameObject.SetActive(true);
        muzzleFire.Play();
        impact.gameObject.SetActive(true);
        fireAudio.Play();
        sightAnime.SetBool(animeCtrlName, true);
        Ray ray = FirstPersonCamera.ScreenPointToRay(new Vector3(raycastPose.x, raycastPose.y, 0));

        while (bullet > 0)
        {
            raycastPose = getSightPosToScreen();
            //Debug.Log(raycastPose);
            ray = FirstPersonCamera.ScreenPointToRay(new Vector3(raycastPose.x, raycastPose.y, 0));
            gameSceneFire(ray, shotDistance,
                          (hit) =>
            {
                impactPos.position = hit.point;
                impactPos.LookAt(hit.point - hit.normal);
                impactPos.transform.Translate(Vector3.back * 0.01f);
                if (!impact.isPlaying)
                {
                    impact.Play();
                }
                hitEnemy         = hit.collider.gameObject;
                colliderLog.text = hit.point.ToString();
            },
                          () => { impact.Stop(); });

            /*if(hitEnemy == null)	//舊版作法,使用AR平面感測
             * {
             *      arCoreFire(raycastPose, (hit) =>
             *      {
             *              spark.transform.position = hit.Pose.position;
             *              spark.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.Pose.position);
             *              spark.Play();
             *      });
             * }*/

            if (timing >= fireDelay)
            {
                timing = 0;
                bullet--;
                //刷新AR的虛擬環境碰撞體(深度感測)
                SingleObj <DepthMeshColliderCus> .obj.ScanDepthCollider();

                //對目標造成傷害
                hitEnemy?.GetComponent <Enemy>()?.recvDamage(damage);
                hitEnemy?.GetComponent <BoomBox>()?.recvDamage(damage);
                if (Game.mode != Mode.PVE)
                {
                    hitEnemy?.GetComponentInParent <NetworkPlayer>()?.recvDamage(damage);
                }
                //彈孔殘留效果,延遲5秒後消失(請參考ImpactShowDelay.cs)
                if (hitEnemy?.tag == Constants.tagARCollider)
                {
                    GameObject impactDelay = impactPool.getObj();
                    impactDelay.transform.position = impactPos.position;
                    impactDelay.transform.rotation = impactPos.rotation;
                }
            }
            hitEnemy = null;
            timing  += Time.deltaTime;
            yield return(0);
        }
        fireAudio.Stop();
        muzzleFire.Stop();
        impact.Stop();
        muzzleFire.gameObject.SetActive(false);
        impact.gameObject.SetActive(false);
        sightAnime.SetBool(animeCtrlName, false);
    }
예제 #3
0
    private IEnumerator fireAction()
    {
        // 更新AR環境碰撞體,等待3幀
        SingleObj <DepthMeshColliderCus> .obj.ScanDepthCollider();

        yield return(new WaitForSeconds(0.1f));

        Vector2    raycastPose = getSightPosToScreen();
        GameObject hitEnemy    = null;

        muzzleFire.gameObject.SetActive(true);
        muzzleFire.Play();
        impact.gameObject.SetActive(true);
        fireAudio.Play();
        Ray ray = FirstPersonCamera.ScreenPointToRay(new Vector3(raycastPose.x, raycastPose.y, 0));

        gameSceneFire(ray, shotDistance, (hit) =>
        {
            impactPos.position = hit.point;
            impactPos.LookAt(hit.point - hit.normal);
            impactPos.transform.Translate(Vector3.back * 0.01f);
            if (!impact.isPlaying)
            {
                impact.Play();
            }
            hitEnemy = hit.collider.gameObject;
        }, () => { impact.Stop(); });

        /*if (hitEnemy == null)
         * {
         *      arCoreFire(raycastPose, (hit) =>
         *      {
         *              impact.transform.position = hit.Pose.position;
         *              impact.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.Pose.position);
         *              impact.Play();
         *      });
         * }*/

        if (loaded)
        {
            hitEnemy?.GetComponent <Enemy>()?.recvDamage(damage * 1.5f);
            hitEnemy?.GetComponent <BoomBox>()?.recvDamage(damage * 1.5f);
            if (Game.mode != Mode.PVE)
            {
                hitEnemy?.GetComponentInParent <NetworkPlayer>()?.recvDamage(damage * 1.5f);
            }
        }
        else
        {
            hitEnemy?.GetComponent <Enemy>()?.recvDamage(damage);
            hitEnemy?.GetComponent <BoomBox>()?.recvDamage(damage);
            if (Game.mode != Mode.PVE)
            {
                hitEnemy?.GetComponentInParent <NetworkPlayer>()?.recvDamage(damage);
            }
        }

        //彈孔殘留效果,延遲5秒後消失(請參考ImpactShowDelay.cs)
        if (hitEnemy?.tag == Constants.tagARCollider)
        {
            GameObject impactDelay = impactPool.getObj();
            impactDelay.transform.position = impactPos.position;
            impactDelay.transform.rotation = impactPos.rotation;
        }

        loaded = false;

        sightAnime.SetBool(animeCtrlName, true);

        yield return(new WaitForSeconds(0.3f));

        //fireAudio.Stop();
        muzzleFire.gameObject.SetActive(false);
        impact.gameObject.SetActive(false);
        sightAnime.SetBool(animeCtrlName, false);
    }