Code Review

1 using System;
2 using
UnityEngine;
3 using
UnityStandardAssets.Utility;
4
5 namespace
UnityStandardAssets.Characters.FirstPerson
6 {
7     
public class HeadBob : MonoBehaviour
8     {
9         
public Camera Camera;
10         
public CurveControlledBob motionBob = new CurveControlledBob();
11         
public LerpControlledBob jumpAndLandingBob = new LerpControlledBob();
12         
public RigidbodyFirstPersonController rigidbodyFirstPersonController;
13         
public float StrideInterval;
14         [Range(
0f, 1f)] public float RunningStrideLengthen;
15
16        
// private CameraRefocus m_CameraRefocus;
17         
private bool m_PreviouslyGrounded;
18         
private Vector3 m_OriginalCameraPosition;
19
20
21         
private void Start()
22         {
23             motionBob.Setup(Camera, StrideInterval);
24             m_OriginalCameraPosition = Camera.transform.localPosition;
25        
// m_CameraRefocus = new CameraRefocus(Camera, transform.root.transform, Camera.transform.localPosition);
26         }
27
28
29         
private void Update()
30         {
31           
// m_CameraRefocus.GetFocusPoint();
32             Vector3 newCameraPosition;
33             
if (rigidbodyFirstPersonController.Velocity.magnitude > 0 && rigidbodyFirstPersonController.Grounded)
34             {
35                 Camera.transform.localPosition = motionBob.DoHeadBob(rigidbodyFirstPersonController.Velocity.magnitude*(rigidbodyFirstPersonController.Running ? RunningStrideLengthen :
1f));
36                 newCameraPosition = Camera.transform.localPosition;
37                 newCameraPosition.y = Camera.transform.localPosition.y - jumpAndLandingBob.Offset();
38             }
39             
else
40             {
41                 newCameraPosition = Camera.transform.localPosition;
42                 newCameraPosition.y = m_OriginalCameraPosition.y - jumpAndLandingBob.Offset();
43             }
44             Camera.transform.localPosition = newCameraPosition;
45
46             
if (!m_PreviouslyGrounded && rigidbodyFirstPersonController.Grounded)
47             {
48                 StartCoroutine(jumpAndLandingBob.DoBobCycle());
49             }
50
51             m_PreviouslyGrounded = rigidbodyFirstPersonController.Grounded;
52           
// m_CameraRefocus.SetFocusPoint();
53         }
54     }
55 }


Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *



Code gần giống!

Quản lý chương trình xử lý ảnh C#

Miễn phí
1

Phạm Tuấn Khang

Quản lý thư viện LINQ C#

Miễn phí
1

Phạm Tuấn Khang

Quản lý quán karaoke

Miễn phí
1

Phạm Tuấn Khang

Game xếp hình Tetris C#

Miễn phí
1

Phạm Tuấn Khang