Question by
antymoon · Sep 07, 2015 at 09:21 AM ·
error messagetutorials-start-scripting
PlayerController.cs(8,8): Error CS0029: Cannot implicitly convert type 'UnityEngine.Rigidbody[]' to 'UnityEngine.Rigidbody' (CS0029) (Assembly-CSharp)
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
private Rigidbody rb;
void Start ()
{
rb = GetComponents<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement);
}
}
Comment
Answer by xyz567 · Sep 07, 2015 at 12:58 PM
You have a small typo on the line
rb = GetComponents<Rigidbody>();
Your using "GetComponents" which returns an array of all of a certain component. You should be using just "GetComponent"
Your answer
![](https://koobas.hobune.stream/wayback/20220612032354im_/https://answers.unity.com/themes/thub/images/avi.jpg)