OffSet Position of Player with Camera

 

Just Attach the Script with MainCamera and Tag the Player PlayerM and chagne the offsetX or offsetY values.

   1: private Transform player;
   2:   private float offsetY;
   3:   // Use this for initialization
   4:   void Start ()
   5:   {
   6:       GameObject Player_go = GameObject.FindGameObjectWithTag("PlayerM");
   7:       if (Player_go==null)
   8:       {
   9:           Debug.Log("Object could't fine");
  10:           return;
  11:       }
  12:       player = Player_go.transform;
  13:       offsetY = transform.position.y - player.position.y;
  14:   }
  15:   
  16:   // Update is called once per frame
  17:   void Update () {
  18:       if (player!=null)
  19:       {
  20:           //Its works in js but not in c#
  21:       //   transform.position.x = player.position.x + offsetX;
  22:          Vector3 pos= transform.position;
  23:           pos.y = player.position.y + offsetY;
  24:           transform.position = pos;
  25:       }
  26:   }

Comments