Question by
stefaninkovic · Feb 13, 2017 at 07:08 PM ·
animationerror
Assets/Scripts/ControllerScript.cs(17,72): error CS0029: Cannot implicitly convert type `float' to `UnityEngine.Rigidbody2D'
using System.Collections; using UnityEngine;
public class ControllerScript : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
void Start () {
}
void FixedUpdate () {
float move = Input.GetAxis("Horizontal");
Rigidbody2D myRigidbody = GetComponent<Rigidbody2D>().velocity.y;
if (move > 0 &&!facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
im watching at the moment a tutorial about animations. But im getting this error:
Assets/Scripts/ControllerScript.cs(17,72): error CS0029: Cannot implicitly convert type float' to
UnityEngine.Rigidbody2D'
HEEEEEELP!
Comment
Answer by RobAnthem · Feb 14, 2017 at 12:01 AM
Line 11, you are declaring a variable of type Rigidbody2D, but attempting to set it to the velocity float.
Your answer
![](https://koobas.hobune.stream/wayback/20220612111021im_/https://answers.unity.com/themes/thub/images/avi.jpg)