Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- public float speed = 2.5f;
- public Rigidbody2D rigidbody;
- public float force;
- public float minimalHeight;
- public bool isCheatMode;
- public SpriteRenderer[] renderers;
- private void Start()
- {
- renderers[0].color = Color.red;
- renderers[1].color = Color.yellow;
- renderers[2].color = Color.green;
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKey(KeyCode.A))
- {
- transform.Translate(Vector2.left * Time.deltaTime * speed);
- }
- if (Input.GetKey(KeyCode.D))
- {
- transform.Translate(Vector2.right * Time.deltaTime * speed);
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- rigidbody.AddForce(Vector2.up * force, ForceMode2D.Impulse);
- }
- if (transform.position.y < minimalHeight && isCheatMode)
- {
- transform.position = new Vector2(0, 0);
- rigidbody.velocity = new Vector2(0, 0);
- }
- else if (transform.position.y < minimalHeight && !isCheatMode)
- {
- Destroy(gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement