Search Unity

What's wrong with my code!?

Discussion in 'Scripting' started by Jana1108, Jul 4, 2015.

  1. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    Hi, I'm getting an error from this code can anyone tell me what I need to change?
    This is the error I am getting
    Assets/Scripts/Score.cs(15,17): error CS1525: Unexpected symbol `{'



    using UnityEngine;
    using System.Collections;

    public class Score : MonoBehaviour {

    public GameObject Hoop;

    public int scoreValue = 1;

    // Update is called once per frame
    void Update () {


    if(transform.position.x = Hoop.transform.position.x) & (transform.position.y == Hoop.transform.position.y || transform.position.y == (Hoop.transform.position.y + 2 || transform.position.y == (Hoop.transform.position.y -2)
    {

    UpdateScore()

    }

    }

    void UpdateScore()
    {
    Score.text = "Score: " + scoreValue;
    }


    }
     
  2. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Score : MonoBehaviour {
    5.  
    6. public GameObject Hoop;
    7.  
    8. public int scoreValue = 1;
    9.  
    10. // Update is called once per frame
    11. void Update () {
    12.  
    13.  
    14. if(transform.position.x = Hoop.transform.position.x) & (transform.position.y == Hoop.transform.position.y || transform.position.y == (Hoop.transform.position.y + 2 || transform.position.y == (Hoop.transform.position.y -2)
    15. {
    16.  
    17. UpdateScore()
    18.  
    19. }
    20.  
    21. }
    22.  
    23. void UpdateScore()
    24. {
    25. Score.text = "Score: " + scoreValue;
    26. }
    27.  
    28.  
    29. }
    Use [ code ] tags to format your code, since it makes it easier to read and identify specific lines. Anyways, double check your brackets in the if statement at line 14, since everything needs to be inside the if statement.
     
  3. RiokuTheSlayer

    RiokuTheSlayer

    Joined:
    Aug 22, 2013
    Posts:
    356
    There's a missing ; on line 17
     
  4. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    Thanks, seems to be working fine now :) Check your inbox
     
  5. lordconstant

    lordconstant

    Joined:
    Jul 4, 2013
    Posts:
    389
    In your if statement you are setting the first value not comparing it. Also you should use && not just &.
     
  6. Jana1108

    Jana1108

    Joined:
    Jun 27, 2015
    Posts:
    215
    Thanks its working already