- Home /
Left-hand side of an assignment must be a variable, property or an indexer
Hello, I'm just starting out with unity, and for some practice to get parts of a tutorial in my head, I decided to create my own version of a character controller in C#.. I have figured out how to solve all but one my errors that I get.. which is Left-hand side of an assignment must be a variable, property or an indexer. I have tried to solve this problem but then I get some other silly error which I can't figure out. here's my code :
using UnityEngine;
using System.Collections;
public class capsule_move : MonoBehaviour {
//variables
public float speed ;
public Transform player ;
public float deadzone ;
//functions
//move
void FixedUpdate () {
if (Input.GetAxis("Horizontal") >deadzone) {
player.rigidbody.AddForce = new Vector3(speed,0.0f,0.0f)* Time.deltaTime ;
}
}
}
PLZ HELP MEEHH
Answer by robertbu · Jan 16, 2014 at 08:30 PM
AddForce is a method, not a variable. So you would call it like:
player.rigidbody.AddForce(new Vector3(speed,0.0f,0.0f)* Time.deltaTime);
Note that 'speed' is a good term for the variable used here since the AddForce() pushes the object and therefore does not directly correlate to a specific speed. That is, don't expect your object to move the specific speed used. In fact, without drag, the object will continue to accelerate from this code.
Thanks, I now have a fully working "flip the capsule" scene.. :D now my next task is to figure out how to change the point where the force is added to my rigidbody/ how not to make my capsule flip over by moving without disabling gravity :P
Again Thankyou so much.