- Home /
error CS0029: Cannot implicitly convert type `UnityEngine.CharacterController[]' to `UnityEngine.CharacterController'
hello masters , i'm a newbie n i'm learning . but i'm having trouble when i try play ,show message "error CS0029: Cannot implicitly convert type UnityEngine.CharacterController[]' to
UnityEngine.CharacterController'" i'm use this coding using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour { CharacterController _controller;
// Use this for initialization
void Start () {
_controller = GetComponents<CharacterController>();
}
// Update is called once per frame
void Update () {
Vector3 direction = new Vector3 (Input.GetAxis("horizontal"), 0, Input.GetAxis("vertical"));
_controller.Move (direction);
}
}
help me ,please :(
Answer by DoTA_KAMIKADzE · Apr 23, 2015 at 05:17 PM
Most likely you want to get single character component of type CharacterController, if so then:
//Change this:
_controller = GetComponents<CharacterController>();
//to this:
_controller = GetComponent<CharacterController>();
But if I guessed wrong and you want to get multiple componenets of that type then:
//Change this:
CharacterController _controller;
//to this:
CharacterController[] _controller;
//and then:
_controller[0].Move (direction); //or whichever one you need
yes i want to get single character component , it's work , thanks , :)
Your answer
Follow this Question
Related Questions
Character moving forwards before pressing anything 0 Answers
Compiler Error...Help Needed. 0 Answers
can someone look at my script 1 Answer
White Screen Editor 5.5.2f 2 Answers
Script error CS0029: Cannot implicitly convert type `float' to `bool' 1 Answer