Advertisement
AlexRaynor

2.4 PlatformColors

Sep 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour
  6. {
  7.    public float speed = 2.5f;
  8.     public Rigidbody2D rigidbody;
  9.     public float force;
  10.     public float minimalHeight;
  11.     public bool isCheatMode;
  12.     public SpriteRenderer[] renderers;
  13.  
  14.  
  15.     private void Start()
  16.     {
  17.         renderers[0].color = Color.red;
  18.         renderers[1].color = Color.yellow;
  19.         renderers[2].color = Color.green;
  20.     }
  21.  
  22.  
  23.  
  24.  
  25.     // Update is called once per frame
  26.     void Update()
  27.     {
  28.         if (Input.GetKey(KeyCode.A))
  29.         {
  30.             transform.Translate(Vector2.left * Time.deltaTime * speed);
  31.         }
  32.  
  33.         if (Input.GetKey(KeyCode.D))
  34.         {
  35.             transform.Translate(Vector2.right * Time.deltaTime * speed);
  36.         }
  37.  
  38.         if (Input.GetKeyDown(KeyCode.Space))
  39.         {
  40.             rigidbody.AddForce(Vector2.up * force, ForceMode2D.Impulse);
  41.         }
  42.         if (transform.position.y < minimalHeight && isCheatMode)
  43.         {
  44.             transform.position = new Vector2(0, 0);
  45.             rigidbody.velocity = new Vector2(0, 0);
  46.  
  47.         }
  48.         else if (transform.position.y < minimalHeight && !isCheatMode)
  49.         {
  50.             Destroy(gameObject);
  51.         }
  52.            
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement