How do I put the main camera in my script unity code example
Example 1: how to import camera pos in unity
Camera maincam = GameObject.Find("Main Camera").GetComponent<Camera>(); Debug.Log(maincam.transform.position);
Example 2: how to code a move camera in unity
void Update()
{
if(Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(new Vector3(speed * Time.deltaTime,0,0));
}
if(Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(new Vector3(-speed * Time.deltaTime,0,0));
}
if(Input.GetKey(KeyCode.DownArrow))
{
transform.Translate(new Vector3(0,-speed * Time.deltaTime,0));
}
if(Input.GetKey(KeyCode.UpArrow))
{
transform.Translate(new Vector3(0,speed * Time.deltaTime,0));
}
}