Awake
How do I use Awake
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
15 | void Awake() | 1 |
10 | public void Awake() | 2 |
15 | public void Awake() | 3 |
28 | public void Awake() | 4 |
101 | void Awake() | 5 |
11 | public void Awake() | 6 |
28 | void Awake() | 7 |
12 | public void Awake() | 8 |
12 | public void Awake() | 9 |
92 | void Awake() | 10 |
File name: JumpAndRunMovement.cs
Copy
15 void Awake()
16 {
17 m_Animator = GetComponent
18 m_Body = GetComponent
19 m_PhotonView = GetComponent
20 }
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: NamePickGui.cs
Copy
15 public void Awake()
16 {
17 this.guiCenteredRect = new Rect(Screen.width/2-GuiSize.x/2, Screen.height/2-GuiSize.y/4, GuiSize.x, GuiSize.y);
18 this.chatComponent = this.GetComponent
19
20 if (this.chatComponent != null && chatComponent.enabled)
21 {
22 Debug.LogWarning("When using the NamePickGui, ChatGui should be disabled initially.");
23
24 if (this.chatComponent.chatClient != null)
25 {
26 this.chatComponent.chatClient.Disconnect();
27 }
28 this.chatComponent.enabled = false;
29 }
30
31 string prefsName = PlayerPrefs.GetString(NamePickGui.UserNamePlayerPref);
32 if (!string.IsNullOrEmpty(prefsName))
33 {
34 this.InputLine = prefsName;
35 }
36 }
File name: DemoMecanimGUI.cs
Copy
16 private PhotonAnimatorView m_AnimatorView; // local animatorView. set when we create our character in CreatePlayerObject()
17 private Animator m_RemoteAnimator; // to display the synchronized values on the right side in the GUI. A third player will simply be ignored (until the second player leaves)
28 public void Awake()
29 {
30
31 }
File name: PickupController.cs
Copy
73 // Are we jumping? (Initiated with jump button and not grounded yet)
77 // Are we moving backwards (This locks the camera to not do a 180 degree spin)
81 // When did the user start walking (Used for going into trot after a while)
87 // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
101 void Awake()
102 {
103 // PUN: automatically determine isControllable, if this GO has a PhotonView
104 PhotonView pv = this.gameObject.GetComponent
105 if (pv != null)
106 {
107 isControllable = pv.isMine;
108
109 // The pickup demo assigns this GameObject as the PhotonPlayer.TagObject. This way, we can access this character (controller, position, etc) easily
110 if (this.AssignAsTagObject)
111 {
112 pv.owner.TagObject = this.gameObject;
113 }
114
115 // please note: we change this setting on ANY PickupController if "DoRotate" is off. not only locally when it's "our" GameObject!
116 if (pv.observed is Transform && !DoRotate)
117 {
118 pv.onSerializeTransformOption = OnSerializeTransform.OnlyPosition;
119 }
120 }
121
122
123 moveDirection = transform.TransformDirection(Vector3.forward);
124
125 _animation = GetComponent
126 if (!_animation)
127 Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
128
129 if (!idleAnimation)
130 {
131 _animation = null;
132 Debug.Log("No idle animation found. Turning off animations.");
133 }
134 if (!walkAnimation)
135 {
136 _animation = null;
137 Debug.Log("No walk animation found. Turning off animations.");
138 }
139 if (!runAnimation)
140 {
141 _animation = null;
142 Debug.Log("No run animation found. Turning off animations.");
143 }
144 if (!jumpPoseAnimation && canJump)
145 {
146 _animation = null;
147 Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
148 }
149 }
File name: CubeExtra.cs
Copy
11 public void Awake()
12 {
13 if (photonView.isMine)
14 {
15 this.enabled = false; // Only enable inter/extrapol for remote players
16 }
17
18 latestCorrectPos = transform.position;
19 }
File name: CubeInter.cs
Copy
28 void Awake()
29 {
30 if (photonView.isMine)
31 this.enabled = false;//Only enable inter/extrapol for remote players
32 }
File name: CubeLerp.cs
Copy
12 public void Awake()
13 {
14 if (photonView.isMine)
15 {
16 this.enabled = false; // due to this, Update() is not called on the owner client.
17 }
18
19 latestCorrectPos = transform.position;
20 onUpdatePos = transform.position;
21 }
File name: IELdemo.cs
Copy
12 public void Awake()
13 {
14 if (!PhotonNetwork.connected)
15 {
16 PhotonNetwork.autoJoinLobby = false;
17 PhotonNetwork.ConnectUsingSettings("0.9");
18 }
19 }
File name: ThirdPersonController.cs
Copy
71 // Are we jumping? (Initiated with jump button and not grounded yet)
75 // Are we moving backwards (This locks the camera to not do a 180 degree spin)
79 // When did the user start walking (Used for going into trot after a while)
85 // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
92 void Awake()
93 {
94 moveDirection = transform.TransformDirection(Vector3.forward);
95
96 _animation = GetComponent
97 if (!_animation)
98 Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
99
100 /*
101 public AnimationClip idleAnimation;
102 public AnimationClip walkAnimation;
103 public AnimationClip runAnimation;
104 public AnimationClip jumpPoseAnimation;
105 */
106 if (!idleAnimation)
107 {
108 _animation = null;
109 Debug.Log("No idle animation found. Turning off animations.");
110 }
111 if (!walkAnimation)
112 {
113 _animation = null;
114 Debug.Log("No walk animation found. Turning off animations.");
115 }
116 if (!runAnimation)
117 {
118 _animation = null;
119 Debug.Log("No run animation found. Turning off animations.");
120 }
121 if (!jumpPoseAnimation && canJump)
122 {
123 _animation = null;
124 Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
125 }
126
127 }
Download file with original file name:Awake
Awake 154 lượt xem
Gõ tìm kiếm nhanh...