Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Putting a script on Main Camera

Discussion in 'Scripting' started by jroto23, Oct 27, 2015.

  1. jroto23

    jroto23

    Joined:
    Oct 19, 2015
    Posts:
    82
    So how do I reference the camera? Do I have to use .FindObject or .FindByTag? Since the script is attached to the Main Camera can I use this.Transform.x += 10;
    I'm just throwing Transform out there, atm I have no particular componet or property I want to change, I'm just reading a box and they never went into this.
     
  2. Beer_Huntor

    Beer_Huntor

    Joined:
    Oct 26, 2015
    Posts:
    6
    GetComponent I think.. or find by tag? not sure new to unity myself
     
  3. UltiGamer835

    UltiGamer835

    Joined:
    Jun 5, 2013
    Posts:
    8
    If the script is attached to the Main Camera already you shouldn't have to do anything to reference it, since it's already a part of it. For example:
    Code (CSharp):
    1. void Start(){
    2.      //This moves the camera to the right by 10 units.
    3.      //Simply use "transform" to reference the object that the script is attached to, and the object's position, rotation, and/or scale.
    4.      transform.position = new Vector3(transform.postion.x + 10,0,0);
    5. }