Question by
asadzia321 · Jul 10, 2018 at 01:16 PM ·
c#camera
Change Camera postion
Hi i am a newbie here and want to change the camera position to one cube to an other using a button as i have 4 cube on a plan place in row i want to change the camera position to first cube to second cube when i press the button and so on
Comment
Answer by kalen_08 · Jul 10, 2018 at 09:33 PM
attach this to the button and set the ChangeCamera () as the function of the Button.
using UnityEngine;
using System.Collections;
public class NewBehaviour : MonoBehaviour
{
public Vector3 offset = new Vector3 (0, 0, -10);
public GameObject[] cubeArray;
int index = -1; //so that on start it will then be 0;
Camera camera;
void Start ()
{
camera = Camera.current;
camera.transform.position = cubeArray[index].transform.position
}
public void ChangeCameraView ()
{
index = (index + 1) % cubeArray.length;
camera.transform.position = cubeArray[index].transform.position + offset;
}
}
if this answer helped then mark it as the accepted answer please.
Your answer
Follow this Question
Related Questions
How to do a wall jump? i am very novice 0 Answers
Issue with Rigidbody2D (I think) 2 Answers
How to get depth information from camera and save it per frame? 0 Answers
Why object's doesn't stop on collision enter? 0 Answers
When playing builded version of game the cameras only captures part of scene. 0 Answers