-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
51 lines (46 loc) · 1.41 KB
/
Player.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Player : MonoBehaviour
{
public float speed=10;
public float turnSpeed = 4;
public GameObject prefabMusic;
// Start is called before the first frame update
void Start()
{
var music = GameObject.Find("BgMusic");
if (music == null)
{
var m= Instantiate(prefabMusic,null);
m.name = "BgMusic";
DontDestroyOnLoad(m);
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(0);
Time.timeScale = 1;
return;
}
float x = Input.GetAxis("Horizontal");
transform.Translate(x*turnSpeed*Time.deltaTime, 0, speed * Time.deltaTime);
//Screen Rotate
var c = Camera.main.transform;
Quaternion cur = c.rotation;
Quaternion target = cur * Quaternion.Euler(0, 0, x * 0.3f);
Camera.main.transform.rotation = Quaternion.Slerp(cur,target,0.1f);
if (transform.position.x < -4 || transform.position.x > 4)
{
transform.Translate(0, -10 * Time.deltaTime, 0);
}
if (transform.position.y < -20)
{
Time.timeScale = 0;
}
}
}