- Home /
Trigger animation-function in Update
Hello,
What I'm currently trying to get to work is:
By touching an object the camera focuses it (moves the camera target to the "touched object"). The moving is no problem, but I want the camera move to be animated. Which I have working.
gameObject.Find("Cameratarget").transform.position = Vector3.Lerp(positionOfCameraTarget.position, transform.position, (Time.time)/100);
So what is the question? Well the camera-animation may only be executed when an object is touched and since it's a camera-animation this function (camera-animation) must reside in Update (if I'm correct). So I'm looking for a way to call a function in Update (presumably with an If-statement).
In the Update function: if object is touched then run CameraAnimation-function.
The touch-function is called with a sendmessage "OnTouchObject" in the raycast script:
function Update ()
{
var hit : RaycastHit;
for (var i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
// Construct a ray from the current touch coordinates
var ray = camera.ScreenPointToRay (Input.GetTouch(i).position);
if (Physics.Raycast (ray,hit))
{
hit.transform.gameObject.SendMessage("OnTouchObject");
}
}
}
}
So I suppose if there is a way that I can say that the CamearaAnimation function is activated (in the Update Function) by the OnTouchObject message that would be great.
I've solved it by introducing a variable in the touch-function and using that in an If-statement in Update().