Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraGrid : MonoBehaviour {
  6.  
  7.     public Transform target; //this will be your player
  8.     public Vector2 size; //room size in unity units
  9.     public float speed; //linear smooting between 0 and 1
  10.    
  11.     // Update is called once per frame
  12.     void Update () {
  13.         Vector3 pos = new Vector3( Mathf.RoundToInt(target.position.x / size.x) * size.x, Mathf.RoundToInt(target.position.y / size.y) * size.y, transform.position.z);
  14.         transform.position = Vector3.Lerp(transform.position, pos, speed);
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement