Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PlayerControll : MonoBehaviour
- {
- public float speed = 3;
- public bool IsFlipped = false;
- private Rigidbody2D rb;
- private bool IsGrounded;
- public float distance;
- private GameObject Player;
- public GameObject dialog;
- private SpriteRenderer spRender;
- private GameObject SpriteShop;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- Player = GameObject.Find("Player");
- SpriteShop = GameObject.Find("Shop");
- spRender = GetComponent<SpriteRenderer>();
- }
- // Update is called once per frame
- void Update()
- {
- distance = Vector3.Distance(dialog.transform.position, transform.position);
- if(distance <= 0.6 && Input.GetKeyDown("e"))
- {
- SpriteShop.SetActive(true);
- }
- else if(distance >= 0.6 && Input.GetKeyDown("e"))
- {
- SpriteShop.SetActive(false);
- }
- float horizontalInput = Input.GetAxis("Horizontal");
- transform.Translate(Vector2.right * horizontalInput * speed * Time.deltaTime);
- if(IsFlipped == false && Input.GetKeyDown("a"))
- {
- Flip();
- IsFlipped = true;
- }
- else if(IsFlipped == true && Input.GetKeyDown("d"))
- {
- Flip();
- IsFlipped = false;
- }
- }
- void Flip()
- {
- IsFlipped = !IsFlipped;
- Vector3 scale = transform.localScale;
- scale.x *= -1;
- transform.localScale = scale;
- IsFlipped = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement