- Home /
Start Camera Lerp from diffrent script?
I have created a lerp script and placed it on my camera. and its working when i slide it in the inspector.
when the player mouseUP on an object i want the script that is on the camera to move from point a to b.
how do i tell one script to start the lerp? ugh. im confused.
here is the script i put on the camera
using UnityEngine;
using System.Collections;
public class Camera2 : MonoBehaviour {
private Vector3 Begin_Rotation = new Vector3(0f,0f,0f);
private Vector3 End_Rotation = new Vector3(0f,0f,0f);
public Transform Start_Position;
public Transform End_Position;
public bool LerpIt = true;
float speed = 0.5f;
public bool TimeLerp = true;
public float Lerp_Slider = 0.0f;
private float timer = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Update () {
if(LerpIt)
{
transform.position = Vector3.Lerp(Start_Position.transform.position,End_Position.transform.position, Lerp_Slider);
}
if(!TimeLerp)
{
//resets timer
timer = 0;
}
if (TimeLerp)
{
timer += Time.deltaTime;
transform.eulerAngles = Vector3.Lerp(Begin_Rotation, End_Rotation, timer*speed);
}
}
}
Answer by darthtelle · May 08, 2014 at 07:14 AM
Create a public function in your Camera script which sets the LerpIt flag to true. This can then be called from any other script but updates the Camera script. Below I've included some pseudo-code to demonstrate.
void BeginLerp()
{
LerpIt = true;
}
public class SomeOtherClass
{
void Update()
{
// Insert logic here
GameObject.FindGameObjectByTag("Camera").GetComponent<Camera2>().BeginLerp();
}
}
Your answer
Follow this Question
Related Questions
How to update interval between objects in run time? 0 Answers
Vector3.lerp and then wait 1 Answer
Camera Clamping Third Person? 0 Answers
Vector3.Lerp result in "laggy" movement while running on iOS devices 2 Answers
tell me whats wrong with this lerp 1 Answer