-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cs
More file actions
50 lines (44 loc) · 1.5 KB
/
Player.cs
File metadata and controls
50 lines (44 loc) · 1.5 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed;
public float speedup;
public Rigidbody2D rigidbody;
public float minimalHeight;
public bool isCheatMode;
public SpriteRenderer[] renderers;
public GroundDetection GroundDetection;
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector2.right * Time.deltaTime * speed);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector2.left * Time.deltaTime * speed);
}
if (Input.GetKeyDown(KeyCode.Space) && GroundDetection.isGraund)
{
rigidbody.AddForce(Vector2.up * speedup, ForceMode2D.Impulse);
}
if (Input.GetKeyDown(KeyCode.W) && GroundDetection.isGraund)
{
rigidbody.AddForce(Vector2.up * speedup, ForceMode2D.Impulse);
}
if (Input.GetKeyDown(KeyCode.S))
{
rigidbody.AddForce(Vector2.down * speedup, ForceMode2D.Impulse);
}
if (transform.position.y < minimalHeight && isCheatMode) //обсуждаем выход игрока за пределы игрового мира
{
rigidbody.velocity = new Vector2(10, 0);
transform.position = new Vector3(-3, 1, 0);
}
else if (transform.position.y < minimalHeight)
Destroy(gameObject);
}
}