- Home /
Camera switching with iTween Touch
Hello I am using iTween to control the Camera on a path with Touch (or arrow Keys)
This script (below) works well and gives me a visual editor (yay) But now I want to SWITCH to a New path and still control it with touch
it's a PITA
So I guess the easiest thing is on an event (like a mouse Up) where I want to switch to a new path
is just switch to a New Camera with the same Camera follow Path script on it
Maybe? But it's not working and I am perplexed
Here is My Main Camera follow Path Script:
using UnityEngine;
using System.Collections;
public class FlythroughCameraController1 : MonoBehaviour {
public Transform[] movePath;
public Transform[] lookPath;
public Transform lookTarget;
public float percentage;
//public Transform[] path;
public float speed = 0.1f;
private float redPosition = .16f;
private float bluePosition = .53f;
private float greenPosition = 1;
// private float purplePosition = 1.2;
void Start(){
}
void Update () {
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved) {
percentage += touch.deltaPosition.x * speed / Screen.height;
percentage = Mathf.Clamp01(percentage);
// ROBERTBU iTween.PutOnPath(gameObject,path,percentage);
iTween.PutOnPath(gameObject,movePath,percentage);
iTween.PutOnPath(lookTarget,lookPath,percentage);
transform.LookAt(iTween.PointOnPath(lookPath,percentage));
//transform.LookAt(iTween.PointOnPath(path,percentage+.05f));
}
}
if(Input.GetKey(KeyCode.UpArrow))
{
percentage += speed * Time.deltaTime;
}
if(Input.GetKey(KeyCode.DownArrow))
{
percentage -= speed * Time.deltaTime;
}
percentage = Mathf.Clamp01(percentage);
iTween.PutOnPath(gameObject,movePath,percentage);
iTween.PutOnPath(lookTarget,lookPath,percentage);
transform.LookAt(iTween.PointOnPath(lookPath,percentage));
}
void OnDrawGizmos(){
iTween.DrawPath(movePath,Color.magenta);
iTween.DrawPath(lookPath,Color.cyan);
Gizmos.color=Color.black;
Gizmos.DrawLine(transform.position,lookTarget.position);
}
void SlideTo(float position){
iTween.Stop(gameObject);
iTween.ValueTo(gameObject,iTween.Hash("from",percentage,"to",position,"time",2,"easetype",iTween.EaseType.easeInOutCubic,"onupdate","SlidePercentage"));
}
void SlidePercentage(float p){
percentage=p;
}
}
A mouse Up event happens to switch Cameras, but doesn't seem to work
using UnityEngine;
using System.Collections;
public class MouseUp : MonoBehaviour {
public Camera oldCamera;
public Camera newCamera;
void OnMouseUp()
{
oldCamera.camera.active = false;
newCamera.camera.active = true;
}
}
Any help is greatly appreciated
Thanks
~be
I am not fully understand question but this might be problem. void On$$anonymous$$ouseUp() is only called when game object is having collider is on the gameObject it attached to it. and user click(touch) on the that game object.
Answer by mr-gelmir · Oct 20, 2014 at 08:52 AM
I'm making a wild guess here, but could it have something to do with you getting the camera property from your Camera variable?
you could try this:
public Camera oldCamera;
public Camera newCamera;
void OnMouseUp()
{
oldCamera.enabled = false;
newCamera.enabled = true;
}
now, I'm not sure, but it might be worth trying?
$$anonymous$$r Gelmir
I'm not sure if that's exactly it - but when I switched the old Camera & New Camera in the inspector it worked
Thank you !
Perhaps I might just trigger new scene though - that might be the best idea
Thanks
~be
Your answer
Follow this Question
Related Questions
Alternatives to iTweenPath for creating path for camera 2 Answers
Switching Between (many) different iTween Paths (C#) 0 Answers
iTween even velocity 9 Answers
Scale an iTweenPath 0 Answers
Lerping between Camera Paths 1 Answer