Context: I have a desk chair in my game. This desk chair consists of two separate models (seat & base). I have an animation attached to the chair that makes only the seat spin. I want this animation to play when the user clicks on EITHER the chair OR the base. Therefore I have written a “Best Friend” script that allows me to make relationships between these objects. Whenever the player clicks on an object, it looks for any “Best Friends” and runs any animations on those best friends. It works great!
Problem: My problem is that every time I update and re-import my scene, unity erases all my inspector-made (drag&drop) connections and there are a lot of them in my scene. Therefore I am trying to automate this drag&drop relationship process. I figured I could do this easily with GameObject.Find and GetComponent in an Editor Script or at Runtime but I keep getting Null Reference Exceptions in both cases. My script is below…
function Awake ()
{
// Set All Best Friends
GameObject.Find("Chair2/Chair").GetComponent(VocabWord).bestFriendA = GameObject.Find("Chair1/Chair");
}