Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement