yyl
2025-05-30 0c3a0519a0f526fd67ac3df22fe801c51a81c5e7
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
46
47
using UnityEngine;
using System.Collections;
 
namespace vnxbqy.UI {
    public class PingPongMove:MonoBehaviour {
 
        public Transform reference;
        public Vector3 amplitue;
        public float speed;
 
        Vector3 referencePos = Vector3.zero;
 
        void OnEnable() {
            referencePos = reference == null ? this.transform.localPosition : reference.localPosition;
        }
 
        float x = 0f;
        float y = 0f;
        float z = 0f;
        void LateUpdate() {
 
            if(Mathf.Abs(amplitue.x) > 0.001f) {
                x = referencePos.x - amplitue.x * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.x);
            }
            else {
                x = referencePos.x;
            }
 
            if(Mathf.Abs(amplitue.y) > 0.001f) {
                y = referencePos.y - amplitue.y * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.y);
            }
            else {
                y = referencePos.y;
            }
 
            if(Mathf.Abs(amplitue.z) > 0.001f) {
                z = referencePos.z - amplitue.z * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.z);
            }
            else {
                z = referencePos.z;
            }
 
            this.transform.localPosition = new Vector3(x,y,z);
        }
 
    }
}