So Unity 5 seems to have dropped the separate component MouseLook to instead incorporate it into the FirstPersonController component. I had some code that relied on accessing that component, but now that it’s a “sub-component” I have no idea how to access it.
I started by trying
GameObject.FindObjectWithTag("Player").GetComponent<FirstPersonController>().GetComponent<MouseLook>().enabled = false
–but got the “object reference not set to instance of object” error.
I then tried what’s below. This is a copy/paste of my code as it is right now.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
using UnityStandardAssets.Characters.FirstPerson;
...
public GameObject player;
...
void Update (){
...
player.GetComponent<FirstPersonController>().GetComponent<MouseLook>().enabled = !player.GetComponent<FirstPersonController>().GetComponent<MouseLook>().enabled;
...
}
Yes, I realize I don’t need all of that at the top, but I copied it from the FirstPersonController script in the off-chance it was causing the issue. And there’s a ton of code I didn’t post because it’s somewhat long and unrelated (though I certainly can if it’s desired). And I realize this is almost the same, but I tried in the hopes that assigning the GameObject would somehow help unity understand where to look.
Anyway, got the same problem. I took a look at the FirstPersonController script and saw that the MouseLook part was defined as “private” so I changed it to public–but I got the same issue. So I’m stuck here.
Can anyone give me an example of how to access the MouseLook part of the new FirstPersonController component on the new standard “Player” GameObject? Is it a component within the component? Is it something else? I’d appreciate any help. Thanks.