当前位置: 首页>>代码示例>>C#>>正文


C# NetworkManager.GetMyPosition方法代码示例

本文整理汇总了C#中NetworkManager.GetMyPosition方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkManager.GetMyPosition方法的具体用法?C# NetworkManager.GetMyPosition怎么用?C# NetworkManager.GetMyPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkManager的用法示例。


在下文中一共展示了NetworkManager.GetMyPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HitscanFX

    void HitscanFX(Vector3 startPos, Vector3 endPos)
    {
        Vector3 v = Vector3.zero;
        Vector3 myPos = Vector3.zero;
        Vector3 bulletSound = Vector3.zero;
        Vector3 rayPos = Vector3.zero;
        float x = 0f;

        //visual
        Debug.Log("SniperBulletFX");

        if (sniperBulletFXPrefab != null)
        {
            GameObject sniperFX = (GameObject)Instantiate(sniperBulletFXPrefab, startPos, Quaternion.LookRotation(endPos - startPos));

            LineRenderer lr = sniperFX.transform.Find("LineFX").GetComponent<LineRenderer>();
            if (lr != null)
            {
                lr.SetPosition(0, startPos);
                lr.SetPosition(1, endPos);
            }
            else
            {
                Debug.LogError("sniperBulletFXPrefab's linerenderer is missing.");
            }

            //audio/shooting sound
            sniperBulletFXAudio = sniperBulletFXPrefab.audio.clip;
            nm = GameObject.FindObjectOfType<NetworkManager>();

            if (nm != null && sniperBulletFXAudio != null)
            {
                myPos = nm.GetMyPosition();
                v =  endPos - startPos;
                //get closest position between the other player and shooting ray
                x = (-(Vector3.Dot(startPos, v) -Vector3.Dot(myPos, v)))/(Mathf.Pow(v.x, 2) + Mathf.Pow(v.y, 2) + Mathf.Pow(v.z, 2));
                rayPos = startPos + x * v;

                //test what is the nearest to the enemy
                if (Vector3.Distance(startPos, myPos) < Vector3.Distance(endPos, myPos))
                {
                    if (Vector3.Distance(startPos, myPos) < Vector3.Distance(rayPos, myPos))
                        bulletSound = startPos;
                    else
                    {
                        if (x > 0)  //this ensures, that the shooting player is shooting in your direction
                            bulletSound = rayPos;
                        else
                            bulletSound = startPos;
                    }
                }
                else
                {
                    if (Vector3.Distance(endPos, myPos) < Vector3.Distance(rayPos, myPos) && x > 0)
                        bulletSound = endPos;
                    else
                    {
                        if (x > 0)  //this ensures, that the shooting player is shooting in your direction
                            bulletSound = rayPos;
                        else
                            bulletSound = endPos;
                    }
                }

                AudioSource.PlayClipAtPoint(sniperBulletFXAudio, bulletSound);
                audio.PlayOneShot(sniperBulletFXAudio);
            }
            else
                Debug.LogError("Something went wrong... NetworkManager Audio Shooting");
        }
        else
        {
            Debug.LogError("sniperBulletFXPrefab is missing!");
        }
    }
开发者ID:clemvarois,项目名称:FPS_Unity3D,代码行数:75,代码来源:FXManager.cs


注:本文中的NetworkManager.GetMyPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。