Body









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

Featured Snippets


File name: JumpAndRunMovement.cs Copy
15     void Awake()
16     {
17         m_Animator = GetComponent();
18         m_Body = GetComponent();
19         m_PhotonView = GetComponent();
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: JumpAndRunMovement.cs Copy
52     void UpdateJumping()
53     {
54         if( Input.GetKey( KeyCode.Space ) == true && m_IsGrounded == true )
55         {
56             m_Animator.SetTrigger( "IsJumping" );
57             m_Body.AddForce( Vector2.up * JumpForce );
58             m_PhotonView.RPC( "DoJump", PhotonTargets.Others );
59         }
60     }
File name: JumpAndRunMovement.cs Copy
68     void UpdateMovement()
69     {
70         Vector2 movementVelocity = m_Body.velocity;
71
72         if( Input.GetAxisRaw( "Horizontal" ) > 0.5f )
73         {
74             movementVelocity.x = Speed;
75
76         }
77         else if( Input.GetAxisRaw( "Horizontal" ) < -0.5f )
78         {
79             movementVelocity.x = -Speed;
80         }
81         else
82         {
83             movementVelocity.x = 0;
84         }
85
86         m_Body.velocity = movementVelocity;
87     }
File name: JumpAndRunMovement.cs Copy
89     void UpdateIsRunning()
90     {
91         m_Animator.SetBool( "IsRunning", Mathf.Abs( m_Body.velocity.x ) > 0.1f );
92     }
File name: OnAwakePhysicsSettings.cs Copy
10     public void Awake()
11     {
12         if (!photonView.isMine)
13         {
14             Rigidbody attachedRigidbody = GetComponent();
15             if (attachedRigidbody != null)
16             {
17                 attachedRigidbody.isKinematic = true;
18             }
19             else
20             {
21                 Rigidbody2D attachedRigidbody2d = GetComponent();
22                 if (attachedRigidbody2d != null)
23                 {
24                     attachedRigidbody2d.isKinematic = true;
25                 }
26             }
27         }
28     }
File name: BallControl.cs Copy
20  void Start () {
21   rb2d = GetComponent ();
22   Invoke ("GoBall", 2);
23  }
File name: BallControl.cs Copy
36  void OnCollisionEnter2D(Collision2D coll) {
37   if (coll.collider.CompareTag ("Player")) {
38    vel.x = rb2d.velocity.x;
39    vel.y = (rb2d.velocity.y / 2.0f) + (coll.collider.attachedRigidbody.velocity.y / 3.0f);
40    rb2d.velocity = vel;
41   }
42  }
File name: PlayerControls.cs Copy
14  void Start () {
15   rb2d = GetComponent ();
16  }
File name: PhotonAnimatorViewEditor.cs Copy
66     private void DrawWeightInspector()
67     {
68         SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowLayerWeightsInspector");
69         foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Layer Weights", foldoutProperty.boolValue);
70
71         if (foldoutProperty.boolValue == false)
72         {
73             return;
74         }
75
76         float lineHeight = 20;
77         Rect containerRect = PhotonGUI.ContainerBody(this.m_Animator.layerCount*lineHeight);
78
79         for (int i = 0; i < this.m_Animator.layerCount; ++i)
80         {
81             if (this.m_Target.DoesLayerSynchronizeTypeExist(i) == false)
82             {
83                 this.m_Target.SetLayerSynchronized(i, PhotonAnimatorView.SynchronizeType.Disabled);
84                 EditorUtility.SetDirty(this.m_Target);
85             }
86
87             PhotonAnimatorView.SynchronizeType value = this.m_Target.GetLayerSynchronizeType(i);
88
89             Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + i*lineHeight, containerRect.width, lineHeight);
90
91             Rect labelRect = new Rect(elementRect.xMin + 5, elementRect.yMin + 2, EditorGUIUtility.labelWidth - 5, elementRect.height);
92             GUI.Label(labelRect, "Layer " + i);
93
94             Rect popupRect = new Rect(elementRect.xMin + EditorGUIUtility.labelWidth, elementRect.yMin + 2, elementRect.width - EditorGUIUtility.labelWidth - 5, EditorGUIUtility.singleLineHeight);
95             value = (PhotonAnimatorView.SynchronizeType) EditorGUI.EnumPopup(popupRect, value);
96
97             if (i < this.m_Animator.layerCount - 1)
98             {
99                 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
100                 PhotonGUI.DrawSplitter(splitterRect);
101             }
102
103             if (value != this.m_Target.GetLayerSynchronizeType(i))
104             {
105                 Undo.RecordObject(target, "Modify Synchronize Layer Weights");
106                 this.m_Target.SetLayerSynchronized(i, value);
107
108                 EditorUtility.SetDirty(this.m_Target);
109             }
110         }
111     }

Download file with original file name:Body

Body 116 lượt xem

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