I Need Help With An Error Message!?
When I try to run my game I get Assets/Scripts/PlayerMovement.cs(17,13): error CS0119: Expression denotes a method group', where a
variable', value' or
type' was expected error message. Can somebody please tell me how to fix this?
Here is my code.
using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour { public float moveSpeed; private float maxSpeed = 5f; public Rigidbody rb; private Vector3 input;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (GetComponent<Rigidbody>.velocity.magnitude < maxSpeed)
{
input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
}
GetComponent<Rigidbody>().AddForce(input * moveSpeed);
}
}
Answer by Zoogyburger · May 15, 2016 at 05:35 AM
Please use the 101010 button to format your code. This code needs a rewrite. If you have a reference to your Rigidbody in the void Start() you only need it to get it once. This should help: (Be sure to read through the code to get the idea)
using UnityEngine;
using System.Collections;
public class PlayerMovement {
public float moveSpeed;
private float maxSpeed = 5f;
public Rigidbody rb;
private Vector3 input;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
if (rb.velocity.magnitude < maxSpeed){
{
input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
}
rb.AddForce(input * moveSpeed);
}
}
}
I was able to fix it my code was just outdated and didn't work with unity 5s API thanks a lot doh.
And what is the 101010 button?
Your answer
Follow this Question
Related Questions
Urgent Help Error cs1525! 1 Answer
All the scripts in my project are giving me a CS0103 and CS1061 errors! 1 Answer
How to make Text in canvas disappear on keypress? 2 Answers
Getting 'bouyancy' on water to work. Help! 0 Answers
Input Dispatching issue ANR reports in Unity 3D Game on Android platform 0 Answers