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();
rigidBody = GetComponent();
}
// 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);
}
}
}
↧