I wrote a script for the player of this game I’m working on in class. It worked fine at first when I just implemented the horizontal movement, but when I added the coding for jumping, I got these error messages:
Assets/Scripts/BoyController.cs(22,22): error CS1502: The best overloaded method match for `UnityEngine.Animator.SetBool(string, bool)’ has some invalid arguments
Assets/Scripts/BoyController.cs(22,22): error CS1503: Argument #2' cannot convert
float’ expression to type `bool’
Assets/Scripts/BoyController.cs(40,37): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody2D.AddForce(UnityEngine.Vector2, UnityEngine.ForceMode2D)’
I’m pretty new to scripting, so I’m not entirely sure what these messages are saying. Here’s the script:
using UnityEngine;
using System.Collections;
public class BoyController : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpforce = 700f;
void Start ()
{}
void FixedUpdate ()
{
anim.SetBool ("vSpeed", GetComponent<Rigidbody2D>().velocity.y);
float move = Input.GetAxis ("Horizontal");
GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Update()
{
if(grounded && Input.GetKeyDown(KeyCode.UpArrow))
{
anim.SetBool("Ground", false);
Rigidbody2D.AddForce(new Vector2(0, jumpforce));
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Does anyone know what I need to fix to get rid of those three error messages? Thanks for any help given.