Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

i keep getting this error, can you help?

Discussion in 'Scripting' started by jjcanti, Jul 28, 2015.

  1. jjcanti

    jjcanti

    Joined:
    Jul 28, 2015
    Posts:
    2
    im new, and i tried the roll a ball tutorial project. However, whenever i put in the CameraController script it gives me an error message saying that there is a "compiler error" in the script and it cannot be used, i have tried everything; even copy/pasting the script under the video but still no luck. does anyone have any tips?
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    You can't be going around putting scripts on objects if a compiler error exists in the project. If you want help, you need to provide the details of the error and copy/paste the script that the error is referring to. Use code tags please.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Open up the console by double clicking the error message. This will give you a list of errors. Fix the first one, then recompile. Repeat this process until no more errors remain.

    Focusing on the first error is good practice as many beginner errors, like parsing error or unexpected symbol, can confuse the compiler and make the rest of the error log meaningless.
     
  4. jjcanti

    jjcanti

    Joined:
    Jul 28, 2015
    Posts:
    2
    here's my code:
    using UnityEngine;
    using System.Collections;

    public class CameraController : MonoBehaviour {

    public GameObject Player;

    private Vector3 offset

    Start () {
    offset = transform.position - Player.transform.position;
    }

    void LateUpdate () {
    transform.position = Player.transform.position + offset;
    }
    }


    and the error im getting is:
    Assets/Scripts/CameraController.cs(10,9): error CS1520: Class, struct or interface method must have a return type
     
  5. Fyko-chan

    Fyko-chan

    Joined:
    Sep 29, 2012
    Posts:
    76
    Start (){
    Should be
    void Start (){
     
  6. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Also: code tags!
     
    Kiwasi likes this.
  7. LoLygager2015

    LoLygager2015

    Joined:
    Feb 26, 2016
    Posts:
    1
    could someone help me with mine,i'm rying to get my sprite to move
    it is


    using UnityEngine;
    using System.Collections;
    public class NewBehaviourScript : MonoBehaviour
    public float maxspeed = 10f;
    bool facingright = true
    // Use this for initialization
    void Start()
    {
    }
    // Update is called once per frame
    void FixedUpdate(
    float move = input.GetAxis("Horizontal");
    Rigidbody2D.velocity = new Vector2(move* maxspeed, Rigidbody2D.velocity.y);
    else if ( move > 0 &&!facingright
    Flip();
    void flip()
    FacingRight = !FacingRight
    vector3 thescale = Transform.LocalScale;
    thescale.x* =-1;
    transform.localScale = thescale;
    ) {
    }
    }