-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackUpScript.cs
More file actions
131 lines (102 loc) · 3.96 KB
/
BackUpScript.cs
File metadata and controls
131 lines (102 loc) · 3.96 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using UnityEngine;
public class BackUpScript : MonoBehaviour
{
// // Start is called before the first frame updat
// [SerializeField]
// private GameObject GameManagerObj;
// private GameManager gameManager;
// float horizontalInput;
// float screenWorldUnits;
// float sideSpeed = 5.0f;
// bool gameStarted;//
// void Start()
// {
// //transform.position= new Vector3(0, 0, -4.0f);
// gameManager = GameManagerObj.GetComponent<GameManager>();
// float playerHalfWidth= transform.localScale.x;
// screenWorldUnits= Camera.main.aspect* Camera.main.orthographicSize+ playerHalfWidth;
// }
// // Update is called once per frame
// void Update()
// {
// gameStarted= gameManager.isGameStarted;
// if(gameStarted)
// {
// //MOVEMENT
// horizontalInput= Input.GetAxis("Horizontal");
// transform.Translate(Vector3.right*horizontalInput*Time.deltaTime* sideSpeed);
// if(transform.position.x< -screenWorldUnits)
// {
// transform.position= new Vector3(screenWorldUnits, transform.position.y, transform.position.z);
// }
// if(transform.position.x>screenWorldUnits)
// {
// transform.position= new Vector3(-screenWorldUnits, transform.position.y, transform.position.z);
// }
// }
// }
// -------------------------------------------CODE FOR ARDUINO-----------------------------------------------------------------------------------------------------
// [SerializeField]
// private GameObject GameManagerObj;
// private GameManager gameManager;
// float screenWorldUnits;
// float sideSpeed = 5.0f;
// bool gameStarted;
// SerialPort serialPort = new SerialPort("COM4", 1115200); // Adjust the port and baud rate as needed
// void Start()
// {
// gameManager = GameManagerObj.GetComponent<GameManager>();
// float playerHalfWidth = transform.localScale.x;
// screenWorldUnits = Camera.main.aspect * Camera.main.orthographicSize + playerHalfWidth;
// try
// {
// serialPort.Open();
// }
// catch (System.Exception e)
// {
// Debug.LogError("Error opening serial port: " + e.Message);
// }
// }
// void Update()
// {
// gameStarted = gameManager.isGameStarted;
// if (gameStarted)
// {
// if (serialPort.IsOpen)
// {
// try
// {
// string data = serialPort.ReadLine();
// ParseArduinoData(data);
// }
// catch (System.Exception e)
// {
// Debug.LogError("Error reading from serial port: " + e.Message);
// }
// }
// }
// }
// void ParseArduinoData(string data)
// {
// // Assuming the Arduino sends data in the format "ax,ay,az"
// string[] values = data.Split(',');
// if (values.Length == 3)
// {
// float ax = float.Parse(values[0]);
// float ay = float.Parse(values[1]);
// float az = float.Parse(values[2]);
// // Use the data to control the player's movement
// // Example: transform.Translate(Vector3.right * ax * Time.deltaTime * sideSpeed);
// float movement = ax * Time.deltaTime * sideSpeed;
// // Move the player left or right based on accelerometer data
// transform.Translate(Vector3.right * movement);
// // Limit player movement within the screen bounds
// transform.position = new Vector3(Mathf.Clamp(transform.position.x, -screenWorldUnits, screenWorldUnits), transform.position.y, transform.position.z);
// }
// }
// void OnApplicationQuit()
// {
// if (serialPort.IsOpen)
// serialPort.Close();
// }
}