vpratama

PlayerControl.cs

Nov 6th, 2025
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     public float movespeed = 5f;
  8.     public Transform movePoint;
  9.     public LayerMask whatStopsMovement;
  10.  
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         movePoint.parent = null;        
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         transform.position = Vector3.MoveTowards(transform.position, movePoint.position, movespeed * Time.deltaTime);
  21.         if(Vector3.Distance(transform.position, movePoint.position) <= .05f) {
  22.             if(Mathf.Abs(Input.GetAxisRaw("Horizontal")) == 1f) {
  23.                 if(!Physics2D.OverlapCircle(movePoint.position + new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f), 2f, whatStopsMovement)) {
  24.                     movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f);
  25.                 }
  26.             }
  27.  
  28.             if(Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f) {
  29.                 if(!Physics2D.OverlapCircle(movePoint.position + new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f), 2f, whatStopsMovement)) {
  30.                     movePoint.position += new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f);
  31.                 }
  32.             }
  33.         }
  34.        
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment