UpdateAnimation
How do I use Update Animation
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
48 | UpdateAnimation(); | 1 |
51 | void UpdateAnimation() | 2 |
37 | void UpdateAnimationState(){ | 3 |
57 | UpdateAnimationState (); | 4 |
33 | UpdateAnimation(); | 5 |
37 | private void UpdateAnimation() | 6 |
File name: RPGMovement.cs
Copy
30 void Update()
31 {
32 if( m_PhotonView.isMine == true )
33 {
34 ResetSpeedValues();
35
36 UpdateRotateMovement();
37
38 UpdateForwardMovement();
39 UpdateBackwardMovement();
40 UpdateStrafeMovement();
41
42 MoveCharacterController();
43 ApplyGravityToCharacterController();
44
45 ApplySynchronizedValues();
46 }
47
48 UpdateAnimation();
49 }
File name: RPGMovement.cs
Copy
51 void UpdateAnimation()
52 {
53 Vector3 movementVector = transform.position - m_LastPosition;
54
55 float speed = Vector3.Dot( movementVector.normalized, transform.forward );
56 float direction = Vector3.Dot( movementVector.normalized, transform.right );
57
58 if( Mathf.Abs( speed ) < 0.2f )
59 {
60 speed = 0f;
61 }
62
63 if( speed > 0.6f )
64 {
65 speed = 1f;
66 direction = 0f;
67 }
68
69 if( speed >= 0f )
70 {
71 if( Mathf.Abs( direction ) > 0.7f )
72 {
73 speed = 1f;
74 }
75 }
76
77 m_AnimatorSpeed = Mathf.MoveTowards( m_AnimatorSpeed, speed, Time.deltaTime * 5f );
78
79 m_Animator.SetFloat( "Speed", m_AnimatorSpeed );
80 m_Animator.SetFloat( "Direction", direction );
81
82 m_LastPosition = transform.position;
83 }
File name: EnemyController.cs
Copy
37 void UpdateAnimationState(){
38 if(hitPoints <= 5){
39 animator.SetTrigger ("isDamage");
40 }
41 }
File name: EnemyController.cs
Copy
43 void OnCollisionEnter2D(Collision2D collision){
44 if(collision.relativeVelocity.magnitude > damageCounter){
45 hitPoints -= Mathf.RoundToInt(collision.relativeVelocity.magnitude);
46 UpdateScoreStatus (Mathf.RoundToInt (collision.relativeVelocity.magnitude));
47 if(GameController.instance != null && MusicController.instance != null){
48 if(GameController.instance.isMusicOn){
49 if (gameObject != null) {
50 AudioSource.PlayClipAtPoint (hurt, transform.position);
51 }
52 }
53 }
54 }
55
56
57 UpdateAnimationState ();
58
59 if(hitPoints <= 0){
60 Death ();
61
62 if(collision.gameObject.CompareTag("Player Bullet")){
63 bounce = collision.transform.GetComponent
64 bounce.y = 0f;
65 collision.transform.GetComponent
66
67 }
68 }
69 }
File name: Animation.cs
Copy
29 public void Update()
30 {
31 if (isRunning)
32 {
33 UpdateAnimation();
34 }
35 }
File name: Animation.cs
Copy
37 private void UpdateAnimation()
38 {
39 stateTime += Time.deltaTime;
40 if (stateTime >= durationOneFrame)
41 {
42 if (isFinish)
43 {
44 if (destroyWhenFinish)
45 {
46 Destroy(gameObject);
47 return;
48 }
49 }
50 currentIndex++;
51 if (currentIndex == frame - 1)
52 {
53 if (!repeat)
54 isFinish = true;
55 }
56 if (currentIndex == frame)
57 currentIndex = 0;
58 stateTime = 0;
59 gameObject.GetComponent
60 }
61 }
UpdateAnimation 139 lượt xem
Gõ tìm kiếm nhanh...