- Home /
What is wrong with this code?
This script is dependant on a script called "Camerascrolling" I get no Error, but the script isn't working either..
private var cameraScrolling : CameraScrolling;
private var Selected = 0;
var targets : Transform[];
function Awake () {
cameraScrolling = GetComponent (CameraScrolling);
cameraScrolling.SetTarget (targets[0], true);
for (var i=0; i < targets.Length; i++)
targets[i].gameObject.SendMessage ("SetControllable", (i == 0), SendMessageOptions.DontRequireReceiver);
if (Input.GetKeyDown(KeyCode.Alpha1))
{
cameraScrolling.SetTarget (targets[0], true);
cameraScrolling.SetTarget (targets[1], false);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
cameraScrolling.SetTarget (targets[0], false);
cameraScrolling.SetTarget (targets[1], true);
}
}
Answer by x4000 · May 27, 2011 at 11:42 AM
Without knowing what camera scrolling does, it's hard to really say. Two suggestions:
Make sure that you're actually pressing alpha1 and alpha2; those are the numbers along the top of the keyboard, NOT the ones on the number pad.
Try putting in some Debug.Log calls into your code at various points in that method to see which points are being reached, if any. Right now you don't know if your Awake method is being called at all, if the key events are happening, or what. If all those things are happening, then you have more complex sleuthing to do. But for the moment, best just to knock out the easier-to-verify stuff and go from there.
Your answer
Follow this Question
Related Questions
How to make a 2d game with fixed camera rooms 2 Answers
Smoother camera movement? 2 Answers
My HUD disappears when switching cameras. 0 Answers
How to avoid Camera jerk when mesh count increases ???? 0 Answers
How do I implement this Camera Tracking? 0 Answers