Guest User

CameraTargetChanger

a guest
Jun 20th, 2014
577
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraTargetChanger : MonoBehaviour {
  5.  
  6.     CameraFollow cFollow;
  7.     PlayerMove pMove;
  8.    
  9.     public Transform Target1;
  10.    
  11.     public Vector3 TargetOffset;
  12.    
  13.     public float TargetFollowSpeed;
  14.    
  15.     public bool OnlyTriggerOnce=true;
  16.  
  17.     public bool TargetIsPlayer=false;
  18.  
  19.  
  20.     //We should trigger if the player enters our trigger
  21.     void OnTriggerEnter(Collider other) {
  22.         //If what entered our trigger has the TAG Player...
  23.         if(other.gameObject.tag=="Player") {
  24.             //Let's ask the Camera to give us their Camera Follow component to mess with!
  25.             cFollow = Camera.main.GetComponent<CameraFollow>();
  26.             cFollow.followSpeed=TargetFollowSpeed;
  27.             if(TargetIsPlayer) {
  28.                 cFollow.target=other.gameObject.transform;
  29.             } else {
  30.                 cFollow.target=Target1;
  31.             }
  32.             cFollow.targetOffset=TargetOffset;
  33.            
  34.             //Now, if we want to trigger this again, and not only once...
  35.             if(OnlyTriggerOnce){
  36.                 gameObject.collider.enabled=false;
  37.             }
  38.         }
  39.     }
  40. }
RAW Paste Data