Unity3D - 유니티3D Camera Shaking 카메라 흔들기
Unity 2022. 7. 20. 16:43 |반응형
특정 조건에서 카메라를 흔들어 보자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraShake : MonoBehaviour
{
public float shakeTime = 1.0f;
public float shakeSpeed = 2.0f;
public float shakeAmount = 1.0f;
private Transform cam;
// Start is called before the first frame update
void Start()
{
cam = GameObject.FindGameObjectWithTag("MainCamera").transform;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
StartCoroutine(Shake());
}
}
IEnumerator Shake()
{
Vector3 originPosition = cam.localPosition;
float elapsedTime = 0.0f;
while (elapsedTime < shakeTime)
{
Vector3 randomPoint = originPosition + Random.insideUnitSphere * shakeAmount;
cam.localPosition = Vector3.Lerp(cam.localPosition, randomPoint, Time.deltaTime * shakeSpeed);
yield return null;
elapsedTime += Time.deltaTime;
}
cam.localPosition = originPosition;
}
}
|
'S'키를 누르면 카메라가 진동한다.
반응형
'Unity' 카테고리의 다른 글
Unity3D - 유니티3D Animation Curve 애니메이션 커브 (0) | 2022.07.24 |
---|---|
Unity3D - 유니티3D Guided Missile 유도 미사일 (0) | 2022.07.21 |
Unity3D - 유니티3D AI Navigation NavMesh Components (0) | 2022.07.14 |
Unity3D - 유니티3D 에러/예외 로그 Error/Exception Logging (1) | 2022.07.09 |
Unity3D - 유니티3D 디버깅 Debugging with Visual Studio (0) | 2022.07.09 |