topical media & game development

talk show tell print

lib-unity-presentation-Assets-Player-Scripts-PlayerCamera.cs / cs



  using UnityEngine;
  using System.Collections;
  
  public class PlayerCamera : MonoBehaviour {
  
      private Transform playerTrans;
      private Transform myTrans;
      private float camSpeed;
      void Awake()
      {
          myTrans = transform;
          playerTrans = (Transform)GameObject.FindGameObjectWithTag("Player").transform;
          
      }
  
      void Update()
      {
          camSpeed = Time.deltaTime * 2 ;
  
          Vector3 aimAtPos = playerTrans.position;
          if (FPSWalker.movementDirection == Direction.left)
          {
              aimAtPos.x -= 3;
          }
          else
          {
              aimAtPos.x += 3;
          }
          myTrans.position = new Vector3(Mathf.Lerp(myTrans.position.x, aimAtPos.x, camSpeed), myTrans.position.y, myTrans.position.z);
      }
      
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.