Repository navigation
Expand file tree
/
Copy pathTransform
More file actions
63 lines (51 loc) · 2.28 KB
/
Copy pathTransform
File metadata and controls
63 lines (51 loc) · 2.28 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--------------------------------
Convert transform
public Vector3 destination;
Vector3 point;
Vector3 vector;
Vector3 direction;
void Start()
{
Debug.Log("Local position" + transform.localPosition);
Debug.Log("Local rotation(E)" + transform.localEulerAngles);
Debug.Log("Local rotation" + transform.localRotation);
//The difference between EulerRotation and rotation
//Rotation is a quantanion and eulerangle is Vector3
//Test the direction of a gameobject's vector3
//Transforms destination's position from local space to world space.
point = transform.TransformPoint(destination);
// Transforms destination's vector from local space to world space.
vector = transform.TransformDirection(destination);
// Transforms destination's direction from local space to world space.
direction = transform.TransformDirection(destination);
}
--------------------------------------------------
public class ModifierTransform : MonoBehaviour
{
public Transform targettransform;
public Vector3 orbit;
void Start()
{
transform.Translate(Vector3.forward);
//Move forward as the targettransform object--Z axis
transform.Translate(Vector3.forward, targettransform);
-------------------------------------------------------
//Check distance
float distance=Vector3.Distance(Object1.position, object2.position);
float distance=Vector3.Distance(object1.position,transform.position);
//Set position and rotation at once
//If the syntex required a quternion, use quaternion.Euler to convert
transform.SetPositionAndRotation(new Vector3(1f, 2f, 3f), Quaternion.Euler(Vector3.forward));
//Brutally set the position to the specific place;
//Rotation
transform.Rotate(new Vector3(10f, 20f, 30f));
transform.Rotate(Vector3.forward, 45f);
//Orbit
//The object rotation use a vector as it's rotate center
transform.RotateAround(orbit, Vector3.up, 90f);
//LookAt
transform.LookAt(targettransform);
transform.LookAt(targettransform, Vector3.right);
//Check for change
Debug.Log("The object has changed" + transform.hasChanged);
}