Hi everyone,
I’m just following the Space shooter tutorial,here I got an error while moving the player.Can anyone please help me…I’m new to gaming.I’m using Unity 5.4…
And here is my script…
using UnityEngine;
using System.Collections;
public class Playercontroller : MonoBehaviour
private Rigidbody;
{
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.velocity = movement;
}
}
And the error shows
Assets/Scripts/Playercontroller.cs(5,7): error CS1031: Type expected
Please help me…
thank you …
Here’s the code that works:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public Rigidbody rb;
public float speed;
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.velocity = movement * speed;
}
}
This:
private Rigidbody;
{
should be this:
{
private Rigidbody rb;
Also… Getcomponent
should be GetComponent
. Code is case sensitive!
Hi everyone,
Thank you for your help,
I added code sujjested by @anarhist1994…
It shows no errors…
I entered play mode and hit play button…It don’t move.
I taught to change the speed and gave “speed value = 100”…
Still its not working for me…
I’m attaching the screenshot of my work…Please help me…
Thank you…
private Rigitbody rb;
is wrong, it must be public Rigitbody rb;
you solve it? i meet the situation,i try to print the value of the var “moveHorizontal”, and it show always
“0” when i press 'wasd". i guess the unity platform in windows 10 , the input doesn`t good match with keyboard. then i check Edit–> Project setting–>input ,the property “moveHorizontal” does be '‘ad’,so i thought there exists some bugs in win10,or some step i losed. no anyidea!
,