I am currently using Unity 5.5 and keep getting the same error saying the left side of the assignment must be a varible,propery. or an indexer
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);
GetComponent (rigidbody.velocity) = movement;
}
}
Always use code tags.
Always tell us what line the error is on.
But, I’m betting it’s your GetComponent call
Which probably should be
GetComponent().velocity = movement;
2 Likes
Brathnann:
Always use code tags.
Always tell us what line the error is on.
But, I’m betting it’s your GetComponent call
Which probably should be
GetComponent().velocity = movement;
Thank you very much I tried it and it moves now
USE CODE TAGS.
Thanks.
public class PlayerController : MonoBehaviour
{
public Rigidbody MyRigidbody;
void Awake()
{
if (MyRigidbody == null) MyRigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
Vector3 movement = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
MyRigidbody.MovePosition(movement);
}
}
LaneFox:
USE CODE TAGS.
Thanks.
public class PlayerController : MonoBehaviour
{
public Rigidbody MyRigidbody;
void Awake()
{
if (MyRigidbody == null) MyRigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
Vector3 movement = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
MyRigidbody.MovePosition(movement);
}
}
I don’t know where to put that at here is what my code is currently
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public Boundary boundary;
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis(“Horizontal”);
float moveVertical = Input.GetAxis(“Vertical”);
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
GetComponent().velocity = movement * speed;
GetComponent().position = new Vector3
(
Mathf.Clamp(GetComponent().position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(GetComponent().position.z, boundary.zMin, boundary.zMax)
);
GetComponent().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent().velocity.x * -tilt);
}
}
First - I hate quoting myself…
LaneFox:
USE CODE TAGS.
Second, if you “don’t know where to put that” then you probably need to start here instead of trying to scrub code off the internet.
1 Like
LaneFox:
USE CODE TAGS.
And give threads real titles for gods sake.
1 Like
LaneFox:
First - I hate quoting myself…
Second, if you “don’t know where to put that” then you probably need to start here instead of trying to scrub code off the internet.
Well I’m doing what my Teacher told me to do so
I’m only a “kid” for gods sake
Then this should be a great few lessons to learn from.
Use code tags
Use descriptive thread titles
When you ask for help, pay attention to what the replies say
Make an effort to apply what those replies say
Expect to learn how to fix things yourself instead of exchange broken code for fixed code
well I’ve only been using unity for about 5 hours in total
All the more reason to follow those points.
you don’t think before I started Unity I did