- Home /
How to assign an Prefab to MainBody using script
Hello, how can i manage to assign a object to the Main Rigid body in C#? I try to assign a prefab to the main body;
public Engine[] engineArray;
public Engine leftThrt;
public Engine righttThrt;
engineArray = Object.FindObjectsOfType(typeof(Engine)) as Engine[];
i used this statement to populate the array with all my engines it works fine, but how do i manage to select specific engine i tried
leftThrt = GameObject.FindGameObjectWithTag("LeftThr");
but it obvious give an error Cannot convert gameobject to Engine...
have you tried:
leftThrt = GameObject.FindGameObjectWithTag("LeftThr") as Engine; ?
Answer by Freaking-Pingo · Nov 03, 2013 at 11:02 PM
With all your engines within the engineArray, why don't you just iterate through all of them and identify which one is what?
foreach(Engine i in engineArray)
{
if(i.value == someCondition)
assignEngine();
}
Your answer
Follow this Question
Related Questions
Clone of rigid body prefab destruction if at certain position 3 Answers
CS0176: An error I can't move past with rigidbody raycasting 1 Answer
Wheelcollider requires Rigidbody but already has one 0 Answers
Checking Collision on instantiated object 0 Answers
SOLVED - How to access variable from another script for Instantiate prefab 2 Answers