Vector3









How do I use Vector3
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: Demo2DJumpAndRun.cs Copy
6     void OnJoinedRoom()
7     {
8         if( PhotonNetwork.isMasterClient == false )
9         {
10             return;
11         }
12
13         PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 5.5f, 0 ), Quaternion.identity, 0, null );
14         PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 4.5f, 0 ), Quaternion.identity, 0, null );
15         PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 3.5f, 0 ), Quaternion.identity, 0, null );
16
17         PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 5.5f, 0 ), Quaternion.identity, 0, null );
18         PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 4.5f, 0 ), Quaternion.identity, 0, null );
19         PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 3.5f, 0 ), Quaternion.identity, 0, null );
20     }
File name: JumpAndRunMovement.cs Copy
40     void UpdateFacingDirection()
41     {
42         if( m_Body.velocity.x > 0.2f )
43         {
44             transform.localScale = new Vector3( 1, 1, 1 );
45         }
46         else if( m_Body.velocity.x < -0.2f )
47         {
48             transform.localScale = new Vector3( -1, 1, 1 );
49         }
50     }
File name: ClickAndDrag.cs Copy
11  void Update ()
12  {
13         if (!photonView.isMine)
14         {
15             return;
16         }
17
18      InputToEvent input = Camera.main.GetComponent();
19      if (input == null) return;
20         if (!following)
21         {
22             if (input.Dragging)
23             {
24                 camOnPress = this.transform.position;
25                 following = true;
26             }
27             else
28             {
29                 return;
30             }
31         }
32         else
33         {
34             if (input.Dragging)
35             {
36                 Vector3 target = camOnPress - (new Vector3(input.DragVector.x, 0, input.DragVector.y) * factor);
37                 this.transform.position = Vector3.Lerp(this.transform.position, target, Time.deltaTime*.5f);
38             }
39             else
40             {
41                 camOnPress = Vector3.zero;
42                 following = false;
43             }
44         }
45  }
File name: InstantiateCube.cs Copy
12     void OnClick()
13     {
14         if (PhotonNetwork.connectionStateDetailed != PeerState.Joined)
15         {
16             // only use PhotonNetwork.Instantiate while in a room.
17             return;
18         }
19
20         switch (InstantiateType)
21         {
22             case 0:
23                 PhotonNetwork.Instantiate(Prefab.name, this.transform.position + 3*Vector3.up, Quaternion.identity, 0);
24                 break;
25             case 1:
26                 PhotonNetwork.InstantiateSceneObject(Prefab.name, InputToEvent.inputHitPos + new Vector3(0, 5f, 0), Quaternion.identity, 0, null);
27                 break;
28         }
29     }
File name: OnClickRequestOwnership.cs Copy
8     public void OnClick()
9     {
10         if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
11         {
12             Vector3 colVector = new Vector3( Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ) );
13             this.photonView.RPC( "ColorRpc", PhotonTargets.AllBufferedViaServer, colVector );
14         }
15         else
16         {
17             if( this.photonView.ownerId == PhotonNetwork.player.ID )
18             {
19                 Debug.Log( "Not requesting ownership. Already mine." );
20                 return;
21             }
22
23             this.photonView.RequestOwnership();
24         }
25     }
File name: OnClickRequestOwnership.cs Copy
28     public void ColorRpc( Vector3 col )
29     {
30         Color color = new Color( col.x, col.y, col.z );
31         this.gameObject.GetComponent().material.color = color;
32     }
File name: OnJoinInstantiate.cs Copy
13     public void OnJoinedRoom()
14     {
15         Vector3 pos = Vector3.zero;
16         pos.x += PhotonNetwork.player.ID;
17
18         if (!InstantiateSceneObjects)
19         {
20
21              newObj = PhotonNetwork.Instantiate(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
22
23
24             // anything you do with newObj locally is not reflected on the other clients.
25             // you can add a script to the Prefab to do some instantiation in Awake() and you can call RPCs on newObj now.
26         }
27         else
28         {
29             newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
30             //PhotonView pv = newObj.GetComponent() as PhotonView;
31             //Debug.Log(pv.ownerId + " " + pv.viewID);
32         }
33     }
File name: MoveCam.cs Copy
13  void Start ()
14     {
15         camTransform = GetComponent().transform;
16      originalPos = camTransform.position;
17
18         randomPos = originalPos + new Vector3(Random.Range(-2, 2), Random.Range(-2, 2), Random.Range(-1, 1));
19     }
File name: MoveCam.cs Copy
22     private void Update()
23     {
24         camTransform.position = Vector3.Slerp(camTransform.position, randomPos, Time.deltaTime);
25         camTransform.LookAt(lookAt);
26         if (Vector3.Distance(camTransform.position, randomPos) < 0.5f)
27         {
28             randomPos = originalPos + new Vector3(Random.Range(-2, 2), Random.Range(-2, 2), Random.Range(-1, 1));
29         }
30     }
File name: DemoMecanimGUI.cs Copy
192     private void CreatePlayerObject()
193     {
194         Vector3 position = new Vector3( -2, 0, 0 );
195         position.x += Random.Range( -3f, 3f );
196         position.z += Random.Range( -4f, 4f );
197
198         GameObject newPlayerObject = PhotonNetwork.Instantiate( "Robot Kyle Mecanim", position, Quaternion.identity, 0 );
199         m_AnimatorView = newPlayerObject.GetComponent();
200     }

Vector3 135 lượt xem

Gõ tìm kiếm nhanh...