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

littl problem

Discussion in 'Scripting' started by ganixx, Oct 6, 2015.

  1. ganixx

    ganixx

    Joined:
    Feb 2, 2015
    Posts:
    29
    hi

    i have the next problem:

    i try to make this code run in c; but i don´t se where is the problem maybe is in the sintax:


    void Update ()
    {
    if(Input.GetMouseButtonDown(1))
    {
    isZoomed = !isZoomed;
    }

    if(isZoomed == true)
    {
    GetComponent.<Camera>().fieldOfView = Mathf.Lerp(GetComponent.<Camera>().fieldOfView, zoom, Time.deltaTime * smooth);
    imageBino.enabled = true;
    }

    else
    {
    GetComponent.<Camera>().fieldOfView = Mathf.Lerp(GetComponent.<Camera>().fieldOfView, normal, Time.deltaTime * smooth);
    imageBino.enabled = false;
    }


    tks :)
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,745
    Use [code ] code tags[/code], it makes things easier to read.

    At least one problem I see right away: In C#, it's GetComponent<Camera>() (no dot in between).

    Though this isn't your problem, you should not be calling GetComponent on the same component every frame.
    Code (csharp):
    1. private Camera myCamera;
    2. void Awake() {
    3. myCamera = GetComponent<Camera>();
    4. }
    5. void Update() {
    6. myCamera.fieldOfView = whatever;
    7. }
     
  3. ganixx

    ganixx

    Joined:
    Feb 2, 2015
    Posts:
    29
    ok thanks for your help and your suggestions abaout to use [code ]