- Home /
Roll-a-Ball project error trying to AddForce
Hi Everyone. I am doing the Roll-a-Ball tutorial and am stuck early on. I am on lesson 3 here: http://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-player
Below is my C# code, which is literally the SAME as the one in tutorial video, but I keep getting the "Expression denotes a type where a variable, value or method group was expected" error when I hit save. There are 3 errors all on the last line.
I browsed similar error questions but those were unable to help. Thanks!
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement);
}
}
you can double click on the error and it highlights the error in the script, most of the times
thanks. so i quit monodevelop and restarted, and the errors disappeared (they were on line 8) the code is not showing up in my inspector though. when i click "open" it takes me to this code in monodevelop how do i make it show in inspector?
you can only see code in unity when you click on the actual script file in project hierarchy, but you cant edit it from unity itself
ok guys so i restarted Unity as well. and the code showed up in inspector and play works / ball moves.
THAN$$anonymous$$S
Answer by Mmmpies · Feb 07, 2015 at 07:02 PM
Odd Your script works perfectly, I just created that scene with this full script (using statements included)
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement);
}
}
im pretty sure something else in his script causes problems, maybe variables in there declared
Yeah but I copied and pasted the code from the question, so only the headers left or something outside the code.
thanks mmmpies.
as i said in the comment above i restarted monodevelop and the errors disappeared.
the code is not showing up in the Inspector though? when i click on open it takes me to monodevelop but how do i make it appear in inspector?
Sorry @Gypsy1 was night time where I am. If you click on the script in assets (probably in a scripts folder) you can see the file in the inspector but its not a good way of viewing scripts. Better to double click and let mono open it.
If you have public variables in a script and you've dragged the script onto an object in the hierarchy you can also play the game with $$anonymous$$aximizeOnPlay unselected and then select the object in the hierarchy. That way you can see the variables value whilst playing, very handy for debugging.
But that script is fine, I suspect Unity/$$anonymous$$ono had a $$anonymous$$or memory glitch. If it keeps happening first try reinstalling Unity, if it continues after that get some memory testing software but for a one off I wouldn't worry about it.
Sorry for any typo's typing on my phone.
Answer by XRuinX · Mar 06, 2015 at 03:34 PM
I just had this same problem..... I've searched for the past hour and a half before coming to find out that simply restarting Unity would fix the problem. I was getting error CS0120 regarding rigidbody.addforce and was sure it was my code but I had made 0 changes to it and it fixed itself on restart. lol oh well, hopefully others stumble across this page, even as closure so they'll know the quick fix next time (after a good look at the code that it:D )
In Unity 5 I added a small upward impulse force to a cube for 1 single frame.
This caused the cube to rocket into space and it was accelerating exponentially.
Fixed on restart!
Answer by Sefat · Nov 22, 2016 at 09:07 AM
I do same as in the video but i got the same problem it shows one error on AddFoce I am new in unity so some one help me....
Your answer
Follow this Question
Related Questions
labyrinth like game 1 Answer
Error on Roll a Ball script Assets/scripts/playercontroller.cs(26,1): error CS8025: Parsing error 1 Answer
Potholes to roll the ball 0 Answers
why is my sphere reddish 1 Answer
Virtual joystick for roll a ball game 0 Answers