Advertisement
Guest User

Untitled

a guest
Jun 20th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class PlayerControll : MonoBehaviour
  7. {
  8.     public float speed = 3;
  9.     public bool IsFlipped = false;
  10.     private Rigidbody2D rb;
  11.     private bool IsGrounded;
  12.     public float distance;
  13.     private GameObject Player;
  14.     public GameObject dialog;
  15.     private SpriteRenderer spRender;
  16.     private GameObject SpriteShop;
  17.    
  18.  
  19.     // Start is called before the first frame update
  20.     void Start()
  21.     {
  22.         rb = GetComponent<Rigidbody2D>();
  23.  
  24.         Player = GameObject.Find("Player");
  25.         SpriteShop = GameObject.Find("Shop");
  26.         spRender = GetComponent<SpriteRenderer>();
  27.     }
  28.  
  29.     // Update is called once per frame
  30.     void Update()
  31.     {
  32.         distance = Vector3.Distance(dialog.transform.position, transform.position);
  33.  
  34.         if(distance <= 0.6 && Input.GetKeyDown("e"))
  35.         {
  36.             SpriteShop.SetActive(true);
  37.         }
  38.         else if(distance >= 0.6 && Input.GetKeyDown("e"))
  39.         {
  40.             SpriteShop.SetActive(false);
  41.         }
  42.  
  43.         float horizontalInput = Input.GetAxis("Horizontal");
  44.         transform.Translate(Vector2.right * horizontalInput * speed * Time.deltaTime);
  45.         if(IsFlipped == false && Input.GetKeyDown("a"))
  46.         {
  47.             Flip();
  48.             IsFlipped = true;
  49.         }
  50.         else if(IsFlipped == true && Input.GetKeyDown("d"))
  51.         {
  52.             Flip();
  53.             IsFlipped = false;
  54.         }
  55.  
  56.     }
  57.     void Flip()
  58.     {
  59.         IsFlipped = !IsFlipped;
  60.         Vector3 scale = transform.localScale;
  61.         scale.x *= -1;
  62.         transform.localScale = scale;
  63.         IsFlipped = false;
  64.        
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement