- Home /
Issues with script in unity 5.4.5p5 and VS 2017
Hi everyone. I'm learning Unity and scripting because i'm completely new to all of it, and currently I'm watching an instructional video and we are building a flappy bird clone, which seems to be pretty common in instructional videos. But I can't seem to get my player to jump with this script, and i get an error message in the unity console. (Error Message: Assets/Scripts/Player.cs(15,34): error CS0118: Player.rigidBody' is a
field' but a `type' was expected)
I'm using unity 5.4.5p5 and visual studio 2017. The instructor is using Monodevelop with his 5.2 version of unity, and his works fine. Would it be a problem using 5.4.5p5 with VS 2017? Here's the script, and thank you for any help.
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
[SerializeField] private float jumpForce = 100f;
private Animator anim;
private Rigidbody rigidBody;
private bool jump = false;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
rigidBody = GetComponent<rigidBody>();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
anim.Play("Jump");
rigidBody.useGravity = true;
jump = true;
}
}
void FixedUpdate()
{
if (jump == true)
{
jump = false;
rigidBody.velocity = new Vector2(0, 0);
rigidBody.AddRelativeForce(new Vector2(0, jumpForce), ForceMode.Impulse);
}
}
}
Answer by arjun19 · Jul 16, 2018 at 12:09 PM
GetComponent<rigidBody>() must be GetComponent<RigidBody>()
Thank you Argun19 for responding. Unfortunately since I let windows do their usual updates on my PC yesterday, now for some reason Unity won't start. I'll have to figure out whats going on with unity before i can see if that worked.. I appreciate you responding.