I got three CS 1061 Errors while learning Unity as an absolute beginner. Please help me!
I was watching and doing the project from this video, but I encountered three CS 1061 errors on 33:04.
https://www.youtube.com/watch?v=7NktwerZFro∈dex=70&list=WL
The following is my code
using UnityEngine;
using System.Collections;
public class respawn : MonoBehaviour {
private Vector3 startPos;
private Quaternion starRot;
// Use this for initialization
void Start (){
startPos = transform.position;
starRot = transform.rotation;
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "death") {
transform.position = startPos;
transform.rotation = starRot;
GetComponents<Animator>().Play("LOSE00",-1, 0f);
GetComponents<Rigidbody>().velocity = new Vector3(0f, 0f, 0f);
GetComponents<Rigidbody>().angularVelocity = new Vector3(0f, 0f, 0f);
}
}
}
And those are the error I got
error CS1061: Type `UnityEngine.Animator[]' does not contain a definition for `Play' and no extension method `Play' of type `UnityEngine.Animator[]' could be found (are you missing a using directive or an assembly reference?)
error CS1061: Type `UnityEngine.Rigidbody[]' does not contain a definition for `velocity' and no extension method `velocity' of type `UnityEngine.Rigidbody[]' could be found (are you missing a using directive or an assembly reference?)
error CS1061: Type `UnityEngine.Rigidbody[]' does not contain a definition for `angularVelocity' and no extension method `angularVelocity' of type `UnityEngine.Rigidbody[]' could be found (are you missing a using directive or an assembly reference?)
Basiclly what those three line do is to play an animation on a character called unitychan after you died like the one after 33:04 in the video. I am so new to unity, and I really need a help here.
Answer by Dext · May 24, 2016 at 09:08 PM
The devil is in the detail:
Your wrote: GetComponents
You should have written: GetComponent
When you write getcomponents an array will be returned. If you want to access an item of that array you have to pick it by its index.
While getcomponent returns a single component, which you can access directly.