-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.cs
97 lines (81 loc) · 2.19 KB
/
move.cs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class move : MonoBehaviour
{
public Rigidbody rb;
private Vector3 pos;
public ButtonR r;
public ButtonL l;
private bool enableL;
private bool enableR;
public Material[] mat;
public KeyCode one;
public KeyCode two;
public KeyCode three;
public KeyCode four;
private Renderer rend;
public GameObject self;
Vector3 movement;
public int x;
// Start is called before the first frame update
void Start()
{
rend = self.GetComponent<Renderer>();
enableL = true;
enableR = true;
}
// Update is called once per frame
void FixedUpdate()
{
if ((Input.GetKey("d") || r.move == true) && enableR == true)
{
rb.AddForce(1000 * Time.deltaTime, 0, 0);
//transform.Translate(x, 0, 0);
}
if ((Input.GetKey("a") || l.move == true) && enableL == true)
{
rb.AddForce(-1000 * Time.deltaTime, 0, 0);
//transform.Translate(-x, 0, 0);
}
if (transform.position.x >= 50)
{
enableR = false;
rb.velocity = Vector3.zero;
pos = new Vector3(50, transform.position.y, transform.position.z);
transform.position = pos;
}
else
{
enableR = true;
}
if (transform.position.x <= -50)
{
enableL = false;
rb.velocity = Vector3.zero;
pos = new Vector3(-50, transform.position.y, transform.position.z);
transform.position = pos;
}
else
{
enableL = true;
}
if (Input.GetKey(one))
{
rend.material = mat[0];
}
if (Input.GetKey(two))
{
rend.material = mat[1];
}
if (Input.GetKey(three))
{
rend.material = mat[2];
}
if (Input.GetKey(four))
{
rend.material = mat[3];
}
}
}