Question by
copenblend · Mar 30, 2016 at 01:11 PM ·
cameracamera-movement
My Camera will not move with script.
Everything else within the start and update functions works fine, but the camera will not move.
void Start () {
levelManager = FindObjectOfType<LevelManager>();
enemySpawner = FindObjectOfType<EnemySpawner>();
combatSpawner = FindObjectOfType<CombatSpawner>();
takenPositions = combatSpawner.LoadPlayerPosition();
mainCamera = FindObjectOfType<Camera> ();
}
// Update is called once per frame
void Update () {
if (myTurn) {
while(!checkValid || chosenPositions.Contains(new Vector2(xPos, yPos))) {
xPos = Mathf.RoundToInt(Random.Range(1f, 37f));
yPos = Mathf.RoundToInt(Random.Range(-10f, 18f));
checkValid = CheckValid(new Vector2(xPos, yPos));
}
chosenPositions.Add(new Vector2(xPos, yPos));
Vector2 position = new Vector2(xPos, yPos);
if(takenPositions.Contains(new Vector2(xPos, yPos))) {
mainCamera.transform.position = new Vector3(xPos, yPos, 0f);
var goodHit = Instantiate(hit, position, Quaternion.identity);
goodHit.name = "Hit_" + hitNumber;
hitNumber++;
if(hitNumber == 15) {
levelManager.LoadLevel("Lose");
}
} else {
mainCamera.transform.position = new Vector3(xPos, yPos, 0f);
var goodMiss = Instantiate(miss, position, Quaternion.identity);
goodMiss.name = "Miss_" + missNumber;
missNumber++;
}
myTurn = false;
}
}
Comment
Have you tried debugging some of your values here? I would suggest making sure that the camera variable contains the main camera object, and that your 'xPos' and 'yPos' variables are being updated with values other than zero. Adding some calls to Debug.Log() inside your 'if' and 'while' statements may also help you to deter$$anonymous$$e if certain code is actually being reached.
Your answer
Follow this Question
Related Questions
Clamping when Zoom changes? 0 Answers
Switching Cameras, Movement not working. 1 Answer
Move camera to look around with mouse 0 Answers
Does anyone know the script for a smooth camera follow of the main game object? 8 Answers
help with switching camera 0 Answers