how do i use get component in unity 5? the code below is just an example, it's not mine but it's similar and also doesn't work
MouseLook cameraScript;
CharacterMotor controllerScript;
FPSInputController controllerScript2;
CharacterController charControl;
GameObject cam;
public void Awake()
{
cameraScript = GetComponent<MouseLook>();
controllerScript = GetComponent<CharacterMotor>();
controllerScript2 = GetComponent<FPSInputController>();
charControl = GetComponent<CharacterController>();
}
public void Start()
{
if (photonView.isMine)
{
cameraScript.enabled = true;
controllerScript.enabled = true;
controllerScript2.enabled = true;
charControl.enabled = true;
}
else
{
enabled = true;
cameraScript.enabled = true;
controllerScript.enabled = true;
controllerScript2.enabled = true;
charControl.enabled = true;
}
What do you mean it doesn't work? This code should work fine. What error do you have? Do you have all Component attached in the Inspector?
the names of the scripts turn into red as soon as i type them, and i think it pops up a error, for some reason isn't showing anymore but still doesn't work
Can you please post example script so we can see what you trying to do?
using UnityEngine;
using System.Collections;
public class Networking : Photon.$$anonymous$$onoBehaviour {
FirstPersonController Char;
void Awake()
{
Char = GetComponent<FirstPersonController> ();
}
// Use this for initialization
void Start () {
PhotonNetwork.ConnectUsingSettings ("RP_v005");
Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
Cursor.visible = (false);
if (photonView.is$$anonymous$$ine)
{
Char.enabled = true;
}
else
{
enabled = true;
Char.enabled = false;
}
}
// Update is called once per frame
void Update () {
Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
Cursor.visible = (false);
}
void OnGUI() {
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Escape))
{
PhotonNetwork.LoadLevel("$$anonymous$$ain$$anonymous$$enu");
}
}
void OnConnectedTo$$anonymous$$aster() {
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed() {
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("PlayerPrefab", Vector3.zero, Quaternion.identity, 0);
PhotonNetwork.automaticallySyncScene = true;
}
}
And if you move the script to the StandardAssets folder? Or Try using
using Unity.StandardAsseets
Or something like this. I'm answering from phone so can't test it at the moment.
Answer by beyluta · Aug 23, 2015 at 08:16 PM
It's already in the standardassets, and using unity.standardassets didn't work either
Just need to add namespace UnityStandardAssets.Characters.FirstPerson{ and worked just fine, thanks @Positive7
Good to hear. I just installed Unity to my traveling Laptop to test it :D It is really slow also I posted one with the namespace before it was just the wrong one :P
Your answer
Follow this Question
Related Questions
Getting server browser with photon ? 3 Answers
Unity Networking Cannot Join Match - Room Disappears 1 Answer
Fail to Connect to NetworkServer 1 Answer
Unet not connecting over the internet 0 Answers