diff options
author | chai <chaifix@163.com> | 2022-04-16 22:54:46 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-04-16 22:54:46 +0800 |
commit | 0292c4cab3ec686d224da576805478c7e8219865 (patch) | |
tree | 4de6e3f221dbab0f6319b8dbb14a124c1ed8303c /AlienSurvival/Assets/Test/Scripts/TestPeaceMaker.cs | |
parent | 6cf30c620615508705e2e800c04eebb7a45e6e04 (diff) |
*tree
Diffstat (limited to 'AlienSurvival/Assets/Test/Scripts/TestPeaceMaker.cs')
-rw-r--r-- | AlienSurvival/Assets/Test/Scripts/TestPeaceMaker.cs | 95 |
1 files changed, 64 insertions, 31 deletions
diff --git a/AlienSurvival/Assets/Test/Scripts/TestPeaceMaker.cs b/AlienSurvival/Assets/Test/Scripts/TestPeaceMaker.cs index 7b1a43d..b29bf43 100644 --- a/AlienSurvival/Assets/Test/Scripts/TestPeaceMaker.cs +++ b/AlienSurvival/Assets/Test/Scripts/TestPeaceMaker.cs @@ -15,6 +15,23 @@ public class TestPeaceMaker : MonoBehaviour [SerializeField] private TestPeaceMakerBullet m_Bullet; [SerializeField] private Vector2 m_Zoom; + private Vector3 zoomIn + { + get + { + Vector3 zin = new Vector3(m_Zoom.x, m_Zoom.x, 1); + return zin; + } + } + private Vector3 zoomOut + { + get + { + Vector3 zout = new Vector3(m_Zoom.y, m_Zoom.y, 1); + return zout; + } + } + private SpriteRenderer m_SpriteRenderer; private TestFakeHeight m_FakeHeight; private Coroutine m_CoFire; @@ -23,6 +40,8 @@ public class TestPeaceMaker : MonoBehaviour private Vector2 m_AimDirection; + private Vector3 m_TargetZoom; + private enum ControlMode { Mouse, @@ -37,19 +56,56 @@ public class TestPeaceMaker : MonoBehaviour m_ControlMode = ControlMode.Mouse; m_AimDirection = Vector2.zero; + + m_TargetZoom = new Vector3(m_Zoom.x, m_Zoom.x, 1); } void Update() { + bool isMove = Move(); + + SetAim(); + + bool isFire = Fire(); + + CameraFollow(); + + CameraZoom(/*isMove ||*/ isFire); + } + + void CameraZoom(bool zout) + { + if(zout) + { + m_TargetZoom = zoomOut; + m_Camera.localScale = Vector3.Lerp(m_Camera.localScale, m_TargetZoom, 0.25f); + } + else + { + m_TargetZoom = zoomIn; + m_Camera.localScale = Vector3.Lerp(m_Camera.localScale, m_TargetZoom, /*Time.deltaTime * 2f*/0.25f); + } + } + + void CameraFollow() + { + Vector3 pos = m_Camera.position; + pos.x = m_FakeHeight.x; + pos.y = m_FakeHeight.y; + + if (Vector3.Distance(pos, m_Camera.position) > 0.1f) + { + m_Camera.position = Vector3.Lerp(m_Camera.position, pos, 3 * Time.deltaTime); + } + } + + bool Move() + { float x = Input.GetAxisRaw("Horizontal"); float y = Input.GetAxisRaw("Vertical"); - Vector3 targetZoom = Vector3.one; - if (x != 0 || y != 0) { - targetZoom = new Vector3(m_Zoom.y, m_Zoom.y, 1); - Vector2 direction = new Vector2(x, y).normalized; Vector3 position = transform.position; @@ -69,35 +125,10 @@ public class TestPeaceMaker : MonoBehaviour m_Shadow.flipX = true; } } - else - { - targetZoom = new Vector3(m_Zoom.x, m_Zoom.x, 1); - } - - Vector3 zoom = m_Camera.localScale; - m_Camera.localScale = Vector3.Lerp(zoom, targetZoom, Time.deltaTime); - - CameraFollow(); - - SetAim(); - - Fire(); + return x != 0 || y != 0; } - void CameraFollow() - { - Vector3 pos = m_Camera.position; - pos.x = m_FakeHeight.x; - pos.y = m_FakeHeight.y; - - if (Vector3.Distance(pos, m_Camera.position) > 0.1f) - { - m_Camera.position = Vector3.Lerp(m_Camera.position, pos, 3 * Time.deltaTime); - } - - } - void SetAim() { float xAxis = Input.GetAxisRaw("AimHorizontal"); @@ -145,7 +176,7 @@ public class TestPeaceMaker : MonoBehaviour return target; } - void Fire() + bool Fire() { if (Input.GetButtonDown("Fire1") || (Input.GetAxis("GunTrigger") == 1)) { @@ -161,7 +192,9 @@ public class TestPeaceMaker : MonoBehaviour StopCoroutine(m_CoFire); m_CoFire = null; } + return false; } + return true; } IEnumerator coFire(float interval) |