SHARE
TWEET

Untitled

a guest May 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public class PlayerScripts: MonoBehaviour
  4. {
  5.     public float boundary;
  6.     public float playerVelocity;
  7.     Vector3 playerPosition;
  8.     Vector3 mousePos;
  9.  
  10.     void Start() => playerPosition = gameObject.transform.position;
  11.     void Update()
  12.     {
  13.         playerPosition.x = Camera.main.ScreenToWorldPoint ( Input.mousePosition ).x;
  14.  
  15.         playerPosition = new Vector3 ( Mathf.Clamp ( playerPosition.x , -boundary , boundary ) , playerPosition.y , playerPosition.z );
  16.  
  17.         if ( playerPosition.x <= -boundary ) playerPosition = new Vector3 ( boundary - 0.01F , playerPosition.y , playerPosition.z );
  18.         if ( playerPosition.x >= boundary ) playerPosition = new Vector3 ( -boundary + 0.01F , playerPosition.y , playerPosition.z );
  19.  
  20.         if ( playerPosition.x > transform.position.x ) GetComponent<SpriteRenderer> ( ).flipX = true;
  21.         if ( playerPosition.x < transform.position.x ) GetComponent<SpriteRenderer> ( ).flipX = false;
  22.  
  23.         transform.position = playerPosition;
  24.     }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top