SHARE
TWEET

Untitled

a guest May 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Movement : MonoBehaviour
  6. {
  7.  
  8.    
  9.  
  10.     public float speed = 1f;
  11.     public Vector2 boundary;
  12.    
  13.  
  14.     private void FixedUpdate()
  15.     {
  16.  
  17.         Vector2 inputs = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized * speed;
  18.         Vector3 newpos = transform.position;
  19.         newpos += new Vector3(inputs.x, 0, inputs.y);
  20.         newpos = new Vector3(
  21.             Mathf.Clamp(newpos.x, -boundary.x, boundary.x),
  22.             3f,
  23.             Mathf.Clamp(newpos.z, -boundary.y, boundary.y)
  24.             );
  25.  
  26.         transform.position = newpos;
  27.     }
  28.  
  29. }
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