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. Dismiss Notice

Scrip cant be loaded

Discussion in 'Getting Started' started by HungPhungQuang, Aug 4, 2016.

  1. HungPhungQuang

    HungPhungQuang

    Joined:
    Aug 4, 2016
    Posts:
    2
    Hi, I am new in Unity. I am trying to do the tutorial from Unity website - The rolling ball. http://unity3d.com/learn/tutorials/projects/roll-ball-tutorial

    I am stuck when adding the code in to make the ball move. I tried the code from
    http://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/moving-player?playlist=17141

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start ()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     void FixedUpdate ()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24. }
    There is an error like this: .
    2.PNG


    Sometimes, the software told me that it is an issue of code between Lixu, Mac and win. ... I do not know what is it.
    1.PNG

    Can you help please?

    Thank you
    Hung Phung
     
  2. Deleted User

    Deleted User

    Guest

    you can just normalize the line endings, that's just formatting.

    show the errors in the console your code generates, it looks fine. Try a higher speed variable.'

    use Debug.Log on any variables you question to see what their actual status is at runtime.
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    I believe the problem is that your file name does not match the class name. The file is PlayerControler.cs (misspelled with one "l"), but the class is PlayerController. Fix the spelling of the file name and it will work better.
     
    tedthebug and Ryiah like this.
  4. HungPhungQuang

    HungPhungQuang

    Joined:
    Aug 4, 2016
    Posts:
    2
    Hi,
    Thanks for replly. About the formatting, how can I fix it? I am a bit confused... is the format of the code different between operations? I only use Windows.

    oh no !!!I think i must made that mistake :(
     
  5. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Just press yes on the formatting pop up, that's what I do.
     
    Ryiah likes this.