Skip to content

Commit 3c8bb56

Browse files
committed
added move test script
1 parent 2db0947 commit 3c8bb56

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace ZO.Util {
6+
7+
[RequireComponent(typeof(Rigidbody))]
8+
public class ZOMoveTest : MonoBehaviour {
9+
10+
public Vector2 _minMax = new Vector2(0, 1.0f);
11+
public float _speed = 0.0f;
12+
// public float _time = 1.0f;
13+
14+
public enum MoveTypeEnum {
15+
RotateRoll,
16+
RotatePitch,
17+
RotateYaw,
18+
TranslateForward,
19+
TranslateRight,
20+
TranslateUp
21+
}
22+
23+
public MoveTypeEnum _moveType = MoveTypeEnum.RotateRoll;
24+
25+
26+
private Rigidbody _rigidBody;
27+
private float _currentValue = 0;
28+
private bool _isRunning = false;
29+
private Vector3 _startRotationEuler = new Vector3();
30+
private Vector3 _startPosition = new Vector3();
31+
32+
33+
// Start is called before the first frame update
34+
void Start() {
35+
_rigidBody = GetComponent<Rigidbody>();
36+
37+
38+
}
39+
40+
void Update() {
41+
if (Input.GetKeyDown(UnityEngine.KeyCode.Space) && _isRunning == false) {
42+
_currentValue = _minMax.x;
43+
_isRunning = true;
44+
_startRotationEuler = transform.rotation.eulerAngles;
45+
_startPosition = transform.position;
46+
}
47+
}
48+
49+
// Update is called once per frame
50+
void FixedUpdate() {
51+
if (_isRunning) {
52+
if (_moveType == MoveTypeEnum.RotateRoll) {
53+
Quaternion rotation = Quaternion.Euler(_startRotationEuler + new Vector3(0, 0, _currentValue));
54+
_rigidBody.MoveRotation(rotation);
55+
} else if (_moveType == MoveTypeEnum.RotatePitch) {
56+
Quaternion rotation = Quaternion.Euler(_startRotationEuler + new Vector3(_currentValue, 0, 0));
57+
_rigidBody.MoveRotation(rotation);
58+
} else if (_moveType == MoveTypeEnum.RotateYaw) {
59+
Quaternion rotation = Quaternion.Euler(_startRotationEuler + new Vector3(0, _currentValue, 0));
60+
_rigidBody.MoveRotation(rotation);
61+
} else if (_moveType == MoveTypeEnum.TranslateForward) {
62+
Vector3 velocity = new Vector3(0, 0, _currentValue);
63+
_rigidBody.MovePosition(_startPosition + velocity);
64+
} else if (_moveType == MoveTypeEnum.TranslateRight) {
65+
Vector3 velocity = new Vector3(_currentValue, 0, 0);
66+
_rigidBody.MovePosition(_startPosition + velocity);
67+
} else if (_moveType == MoveTypeEnum.TranslateUp) {
68+
Vector3 velocity = new Vector3(0, _currentValue, 0);
69+
_rigidBody.MovePosition(_startPosition+ velocity);
70+
}
71+
72+
_currentValue = _currentValue + (_speed * Time.fixedDeltaTime);
73+
74+
if (_currentValue > _minMax.y) {
75+
_isRunning = false;
76+
}
77+
78+
}
79+
80+
}
81+
}
82+
}

Runtime/Scripts/Util/GameObject/ZOMoveTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)