This binds a script to the main camera.
The script is written as:
Using unityengine;using System.collections;public class Camerafollow:monobehaviour {//main camera Follow lead move public float X Margin = 1f; public float ymargin = 1f; public float xsmooth = 8f; public float ysmooth = 8f; Public Vector2 Maxxandy; Public Vector2 minxandy;//with this for initialization private Transform player;void Start () {
Here get is the binding protagonist, need to follow the move together, to get the protagonist's property player = Gameobject.findgameobjectwithtag ("Pk_0"). Transform; maxxandy.x = 10; MAXXANDY.Y = 10;} BOOL Checkxmargin () {return mathf.abs (transform.position.x-player.position.x) > Xmargin; } bool Checkymargin () {return mathf.abs (TRANSFORM.POSITION.Y-PLAYER.POSITION.Y) > Ymargin; }//update is called once per framevoid update () {Trackplayer ();} Trailing protagonist void Trackplayer () {float targetx = transform.position.x; float targety = TRANSFORM.POSITION.Y; if (Checkxmargin ()) {targetx = Mathf.lerp (transform.position.x, player.position.x, Xsmooth * Time.delta Time); } if (Checkymargin ()) {targety = Mathf.lerp (TRANSFORM.POSITION.Y, PLAYER.POSITION.Y, Xsmooth * T Ime.deltatime); } Targetx = Mathf.clamp (Targetx, minxandy.x, MAXXANDY.Y); Targety = Mathf.clamp (targety, MINXANDY.Y, MAXXANDY.Y); Transform.position = new Vector3 (Targetx, targety,transform.position.z); }}
:
Unity3d Camera follows the protagonist to move