Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BenjiBoy · Jun 12, 2015 at 12:51 AM · scripting problemmovementtutorialnewbie

Script I copied from Movement tutorial doesnt work

Hi, newbie here. I followed this tutorial: "Moving the Player" "https://unity3d.com/es/learn/tutorials/projects/roll-a-ball/moving-the-player" ,and copied the script, this is my script:

using UnityEngine;

using System.Collections;

public class PlayerController : MonoBehaviour {

 public float speed;
 private Rigidbody rb;
 void Start ()
 {
     rb = GetComponent<Rigidbody>();
 }
 void FixedUpdate ()
 {
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
     rb.AddForce (movement);
 }

}

And is attached to the ball wich has "Player" as name. When I try to play, the console window it says: "The referenced script on this Behaviour is missing!". Twice.

On the inspector window, under the script that has "movementBall" as name, it says: "The associated script can not be loaded. Please fix any compile errors and assign a valid script". I made sure that the bal has the rigid body component.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Gardes · Jun 12, 2015 at 02:24 AM

It seems your script is named wrong.

 public class PlayerController : MonoBehaviour {

If your class is "PlayerController.cs" your script has to be named as PlayerController.cs and not as "movementBall.cs". So finally scriptname has to be same like classname and vise versa. Name your script PlayerController.cs or change the line I posted before to:

 public class movementBall : MonoBehaviour {
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by unity_037C2224FC8B1C22580C · Aug 20, 2021 at 11:00 AM

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour { public float speed = 0;

 private Rigidbody rb;

 private float movementX;
 private float movementY;

 // Start is called before the first frame update
 void Start()
 {
     rb = GetComponent<Rigidbody>();
 }

 private void OnMove(InputValue movementValue)
 {
     Vector2 movementVector = movementValue.Get<Vector2>();

     movementX = movementVector.x;
     movementY = movementVector.y;
 }

 private void FixedUpdate()
 {
     Vector3 movement = new Vector3(movementX, 0.0f, movementY);

     rb.AddForce(movement * speed);
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I slow down while Im Sliding? 0 Answers

New to Unity & Scripting, How Do I Create a Movement System Thats About Building Up Speed? 0 Answers

Coroutine fires once after destroying gameobjects in a scene and recreating new objects 0 Answers

My Touch Movement Script is Not Working Correctly 1 Answer

Disabling script while in certain position 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges