コード例 #1
0
        private bool Initialize()
        {
            if (!networkObject.IsServer)
            {
                if (networkObject.ownerNetId == 0)
                {
                    _initialized = false;
                    return(_initialized);
                }
            }

            // We're the local owner if the MyPlayerId and ownerNetId match
            _isLocalOwner = networkObject.MyPlayerId == networkObject.ownerNetId;

            //Debug.Log("Initialize.Initialize(): playerID = " + networkObject.playerID + "isLocalOwner = " + _isLocalOwner);
            //Utilities.WriteDebugString(networkObject.playerID, "Initialize.NetworkStart(): playerID = " + networkObject.playerID + "isLocalOwner = " + _isLocalOwner);

            if (_isLocalOwner)
            {
                // Debug.Log("Initialize.NetworkStart(): isLocalOwner");
                //Utilities.WriteDebugString(networkObject.playerID, "Player.NetworkStart(): isLocalOwner");

                // Move the camera to match with the player position in the scene
                mainCamera = Camera.main;
                if (mainCamera != null)
                {
                    //Debug.Log("Initialize.NetworkStart(): moving camera");
                    //Utilities.WriteDebugString(networkObject.playerID, "Player.NetworkStart(): moving camera");

                    // Take the player's position and move it behind and up from the player's position
                    Vector3 newCameraPosition = new Vector3(transform.position.x * 1.1f, 3.5f, 0);
                    mainCamera.transform.position = newCameraPosition;

                    // Have the camera look at the T bar in the scene
                    Vector3 lookAtPosition = new Vector3(0, 3.5f, 0);
                    mainCamera.transform.LookAt(lookAtPosition);
                }
                else
                {
                    Debug.LogError("Player.Initialize(): cannot find main camera");
                }

                // Instantiate the Aim for this player using the aimPositions array
                _myAim = NetworkManager.Instance.InstantiateAim(0, position: aimPositions[networkObject.playerID - 1]);
                _myAim.networkObject.ownerNetId = networkObject.MyPlayerId;
                _myAim.networkObject.playerID   = networkObject.playerID;
            }
            else
            {
                // Debug.Log("Initialize.NetworkStart(): not isLocalOwner");
            }

            // Add an event to trigger when this Player object receives the network Destroy
            networkObject.onDestroy += OnPlayerDestroy;

            _initialized = true;
            return(_initialized);
        }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        //create the game object for the UI (to get the score / # of targets left)
        targetsLeft = GameObject.FindGameObjectWithTag("Score").GetComponent <TargetsLeftUI>();
        //create the scene object to get the active/current scene
        scene = SceneManager.GetActiveScene();

        //creates the game object for the aim
        m_AimDisplay = GameObject.FindGameObjectWithTag("Aim").GetComponent <AimBehavior>();

        //sets the variable for the ball's rigidbody
        m_rb = GetComponent <Rigidbody>();
        Assert.IsNotNull(m_rb, "Houston, we've got a problem here! No Rigidbody attached");

        //sets the aim original position to whatever position the aim is currently in (from the editor)
        m_vAimOriginalPos = m_AimDisplay.getPosition();

        //sets the ball original position to whatever position the ball is currently in (from the editor)
        m_vOriginalPos = transform.position;
    }