-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockAxis.cs
More file actions
31 lines (26 loc) · 889 Bytes
/
Copy pathLockAxis.cs
File metadata and controls
31 lines (26 loc) · 889 Bytes
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
using UnityEngine;
using System.Collections;
public class LockAxis : MonoBehaviour {
public string axis;
private float position;
// Use this for initialization
void Start () {
if(axis == "X"){
position = transform.position.x;
}else if(axis == "Y"){
position = transform.position.y;
}else if(axis == "Z"){
position = transform.position.z;
}
}
// Update is called once per frame
void Update () {
if(axis == "X" && transform.position.x != position){
transform.position = new Vector3(position, transform.position.y, transform.position.z);
}else if(axis == "Y" && transform.position.y != position){
transform.position = new Vector3(transform.position.x, position, transform.position.z);
}else if(axis == "Z" && transform.position.z != position){
transform.position = new Vector3(transform.position.x, transform.position.y, position);
}
}
}