I’m creating an interactive children’s book. Thought I’d do curling pages but decided I didn’t like it for this one. Instead I’ve set up little vignettes for each “page”. When you want to advance to the next page you touch the gui (iPad audience) and change the smoothFollow on the camera to a new target (which is a plane that acts as the target behind the next 3d vignette).
When I do it manually it looks beautiful, the smooth follow repositions the camera as desired. However I can’t figure out the tech part of this to get it all pulled together.
Essentially I have a ControlMenu script attached to the gui, and I want to pass a change back to the smooth follow. Here is the idea.
in SmoothFollow2D script, I have
static var target : Transform ;
In ControlMenu script (attached to the gui)
var cTarget : int = 1 ;
… then lower down in the same script
if (hit >= 0) // has someone touched the page advance button
{
cTarget ++ ;
if (cTarget == 2)
{
SmoothFollow2D.target = camTARGET_2 ; // realign to page 2
}
else blah blah…
}
Makes sense in my mind, but I always seem to be missing some crucial tech stuff on assembling this and would appreciate any help.
cheers
Daev
i think u have to use a public static var in SmoothFollow2D script:
public static var target : Transform ;
and the controls menu i think u have to made a check function called every time cTarget is increased.
var maxPages:integer=100; //max number of pages
var cTarget : int = 1 ; //frist target
var lastTarget : int ; //for check
var nextCamTarget: int; //for update camera target
function checkPage () {
if (cTarget > lastTarget)
{
nextCamTarget++:
lastTarget++;
SmoothFollow2D.target = nextCamTarget ; // realign to page 2
}
function update () {
if (hit < maxPages) // has someone touched the page advance button
{
cTarget ++ ;
checkPage ();
}
else {
debug.Log("finish reading");
}
}
I think it’s not complety correct,but is a correct way to follow.
I found that rather than switching to a new target it worked better to move the current target to a new position. This allows a smooth motion going from one position to another. I set up an array of transforms and then when I wanted to change I would have the target Lerp to the position of the appropriate transform. Makes for a nice camera motion to the new transform.
Bryan
I think the real problem is that the SmoothFollow2D.target = nettCamTarget, will not reassign like my original form.
Looking for how to resolve this.
Bryan,
This seems to again be where my scripting skill breaks down, if you have examples it would be helpful. I’d gladly switch from moving the camera to the moving the target.
Right now I have been struggling to get the camera to obey me using GetComponent.
GameObject.Find(“MainCamera”).GetComponent(SmoothFollow2D).target = “camTARGET_2” ;
The error I receive here is that ‘target’ is not a member of ‘UnityEngine.Component’
thanks for the suggestion and any direction.
dv
On iOS shouldn’t it be (GetComponent(SmoothFollow2D) as SmoothFollow2D).target = “camTARGET_2”; ?
I can’t test it out right away but try that.
hmm… can’t quite get the syntax to work on that, is it java?
thanks
wait I think I got it.
I have to say that Will Goldstone’s book on Unity saves my ass more times than I can say.
GameObject.Find(“camTARGET_1”).transform.position.x = Mathf.Lerp(0,20,2) ;
okay, now I’ll try to finesse the variables to make it automatically calculate for each page turn.
cheers
Daev