unity DOShakePosition
时间: 2024-05-14 22:14:41 浏览: 84
ChangeOfPosition
DOShakePosition is a function in Unity's DOTween library that allows you to shake a GameObject's position.
Here's an example of how to use DOShakePosition:
```c#
using DG.Tweening;
using UnityEngine;
public class ShakeObject : MonoBehaviour
{
private void Start()
{
// Shake the GameObject's position for 1 second with a strength of 0.5 on each axis
transform.DOShakePosition(1f, new Vector3(0.5f, 0.5f, 0.5f));
}
}
```
In this example, we first import the DOTween library and the UnityEngine namespace. Then, in the Start() method, we call the DOShakePosition function on the GameObject's transform component. We pass in two parameters: the duration of the shake (1 second), and the strength of the shake on each axis (0.5 on x, y, and z).
When the game starts, the GameObject will shake for 1 second with a strength of 0.5 on each axis, creating a subtle but noticeable shaking effect.
阅读全文