Question by
nfraga · Jun 01, 2017 at 07:53 AM ·
collidercomponentsattribute
MissingComponentException: There is no 'Rigidbody' attached to the "jeep" game object, but a script is trying to access it.
Hello guys,
Do you know why I have this error message based on this code?
public void AddModelo()
{
GameObject cube = Resources.Load("jeep") as GameObject;
cube.AddComponent<Rigidbody>();
cube.AddComponent<SphereCollider>();
SphereCollider cubeSphCol =cube.GetComponent<SphereCollider>();
Rigidbody cubeRig = cube.GetComponent<Rigidbody>();
cubeRig.useGravity = true;
cube.transform.position = new Vector3(129, 114, -91);
cube.transform.localScale = new Vector3(598.98f, 590.98f, 590.98f);
cubeSphCol.radius = cube.transform.localScale.y;
}
I would like to instatiate objects that I just copy to Resources and add/attribute the components.
Thank you, Nelson
Comment
Your answer
Follow this Question
Related Questions
Not using GetComponent during OnCollisionEnter or OnTriggerEnter 1 Answer
Destroy components sequentially if it has Required Component Attribute 0 Answers
Change Scene with Physics Raycasting 1 Answer
How to make my enemy move in random direction while facing the player 0 Answers
How to Destroy A GameObject when it enters any Triggers 2 Answers