-
Notifications
You must be signed in to change notification settings - Fork 0
/
Runner.cs
60 lines (42 loc) · 1.03 KB
/
Runner.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
using UnityEngine;
using System.Collections;
public class Runner : MonoBehaviour {
public static float distanceTraveled;
public Vector2 speed = new Vector2(50, 50);
private Vector2 movement;
float mouseY = 0;
// Update is called once per frame
void Update () {
//transform.Translate(5f * Time.deltaTime, aggression/25, 0f);
distanceTraveled = transform.localPosition.x;
float inputX = Input.GetAxis("Horizontal");
float inputY = Input.GetAxis("Vertical");
if (Input.GetMouseButtonDown (0))
{
mouseY = 90 * ((Input.mousePosition.y - Screen.height / 2) / (Screen.height / 2));
}
else
{
mouseY = 0;
}
// Movement per direction
//mouse or keyboard
if (mouseY > 0)
{
movement = new Vector2(speed.x * inputX, speed.y);
}
else if (mouseY < 0)
{
movement = new Vector2(speed.x * inputX, -speed.y);
}
else
{
movement = new Vector2(speed.x * inputX, speed.y * inputY);
}
}
void FixedUpdate()
{
// Move the game object
rigidbody2D.velocity = movement;
}
}