Unity HDRP Product Visualizer
1.0.0
Interactive 3D product showcase built with Unity 6 and HDRP
Loading...
Searching...
No Matches
ProductFloatAnimation.cs
Go to the documentation of this file.
1
using
UnityEngine;
2
7
27
public
class
ProductFloatAnimation
: MonoBehaviour
28
{
29
// ------------------------------------------------------------------
30
// Inspector fields
31
// ------------------------------------------------------------------
32
35
37
[Header(
"Float"
)]
38
public
float
floatAmplitude
= 0.05f;
39
41
public
float
floatSpeed
= 1.2f;
42
44
47
49
[Header(
"Tilt"
)]
50
public
float
tiltAmplitude
= 2f;
51
54
public
float
tiltSpeed
= 0.8f;
55
57
58
// ------------------------------------------------------------------
59
// Private state
60
// ------------------------------------------------------------------
61
62
private
Vector3 _startPos;
63
private
float
_offset;
64
65
// ------------------------------------------------------------------
66
// Unity lifecycle
67
// ------------------------------------------------------------------
68
69
void
Start()
70
{
71
_startPos = transform.localPosition;
72
_offset = Random.Range(0f, Mathf.PI * 2f);
73
}
74
76
void
Update()
77
{
78
float
t = Time.time + _offset;
79
80
transform.localPosition = _startPos + Vector3.up * (Mathf.Sin(t *
floatSpeed
) *
floatAmplitude
);
81
82
float
tiltX = Mathf.Sin(t *
tiltSpeed
* 0.7f) *
tiltAmplitude
;
83
float
tiltZ = Mathf.Cos(t *
tiltSpeed
) *
tiltAmplitude
* 0.5f;
84
transform.localRotation = Quaternion.Euler(tiltX, 0f, tiltZ);
85
}
86
}
ProductFloatAnimation
Animates a GameObject with a gentle sinusoidal float and dual-axis tilt.
Definition
ProductFloatAnimation.cs:28
ProductFloatAnimation.floatAmplitude
float floatAmplitude
Peak vertical displacement from the rest position (metres).
Definition
ProductFloatAnimation.cs:38
ProductFloatAnimation.tiltAmplitude
float tiltAmplitude
Peak rotation on X and Z axes (degrees).
Definition
ProductFloatAnimation.cs:50
ProductFloatAnimation.tiltSpeed
float tiltSpeed
Base frequency of the tilt oscillation.
Definition
ProductFloatAnimation.cs:54
ProductFloatAnimation.floatSpeed
float floatSpeed
Cycles per second of the vertical sine wave.
Definition
ProductFloatAnimation.cs:41
UnityVisualizer
Assets
ProductVisualizer
Scripts
ProductFloatAnimation.cs
Generated by
1.9.8