I want a camera that wont move unless my character is at the edge of the screen. I was thinking of using a trigger attached to my camera but I can’t figure out how to use them.
My code for character movement
using UnityEngine;
using System.Collections;
public class CharacterMovement : MonoBehaviour {
private Rigidbody2D rb;
public float moveSpeed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb.MovePosition(rb.position + movement * moveSpeed);
}
}