- Home /
10 errors, need help with my script
I have a code for multiplayer using Photon PUN, but I get ten errors. Can someone help me and/or tell me what's wrong with my code?
Here is my code:
using UnityEngine;
using System.Collections;
public class Multiplayer : Photon.MonoBehaviour {
public GameObject myCamera;
// Use this for initialization
void Start () {
if(photonView.isMine){
myCamera.SetActive(true);
GetComponent<Drivetrain>().enabled = true;
GetComponent<CarController>().enabled = true;
GetComponent<Rigidbody>().useGravity = true;
AntiRollBar[] AntiRollBar = GetComponents<AntiRollBar>();
foreach(AntiRollBar bar in AntiRollBar)bar.enabled = false;
}
else{
myCamera.SetActive(false);
GetComponent<Drivetrain>().enabled = false;
GetComponent<CarController>().enabled = false;
GetComponent<Rigidbody>().useGravity = false;
}
void OnPhotonSerializeView(PhotonStream Stream, PhotonMessageInfo info){
if(stream.isWriting){
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else{
transfrom.position = (Vector3)Stream.RecieveNext();
transfrom.rotation = (Quaternion)Stream.RecieveNext();
}
}
}
}
Here are my errors:
Assets/Photon Unity Networking/Multiplayer.cs(22,42): error CS1547: Keyword
void' cannot be used in this context 2. Assets/Photon Unity Networking/Multiplayer.cs(22,43): error CS1525: Unexpected symbol(', expecting)',,',;',[', or=' 3. Assets/Photon Unity Networking/Multiplayer.cs(27,28): error CS1519: Unexpected symbolelse' in class, struct, or interface member declarationAssets/Photon Unity Networking/Multiplayer.cs(28,52): error CS1519: Unexpected symbol
=' in class, struct, or interface member declaration 5. Assets/Photon Unity Networking/Multiplayer.cs(28,62): error CS1519: Unexpected symbol)' in class, struct, or interface member declarationAssets/Photon Unity Networking/Multiplayer.cs(28,81): error CS1519: Unexpected symbol
(' in class, struct, or interface member declaration 7. Assets/Photon Unity Networking/Multiplayer.cs(29,52): error CS1519: Unexpected symbol=' in class, struct, or interface member declarationAssets/Photon Unity Networking/Multiplayer.cs(29,65): error CS1519: Unexpected symbol
)' in class, struct, or interface member declaration 9. Assets/Photon Unity Networking/Multiplayer.cs(29,84): error CS1519: Unexpected symbol(' in class, struct, or interface member declarationAssets/Photon Unity Networking/Multiplayer.cs(31,17): error CS8025: Parsing error
It literally lists only numbers from 1-5. :) But yeah, if I edit the question I can see all 10. $$anonymous$$ust be a Unity Answers display bug.
Answer by Graham-Dunnett · Jun 17, 2015 at 07:39 PM
You have included your OnPhotonSerializeView() function inside Start(). Move the brace from line 32 to between 21 and 22. (From looking at the code.)
Thanks, I found a typo and now I'm down to 5 errors.
using UnityEngine;
using System.Collections;
public class $$anonymous$$ultiplayer : Photon.$$anonymous$$onoBehaviour {
public GameObject myCamera;
// Use this for initialization
void Start () {
if(photonView.is$$anonymous$$ine){
myCamera.SetActive(true);
GetComponent<Drivetrain>().enabled = true;
GetComponent<CarController>().enabled = true;
GetComponent<Rigidbody>().useGravity = true;
AntiRollBar[] AntiRollBar = GetComponents<AntiRollBar>();
foreach(AntiRollBar bar in AntiRollBar)bar.enabled = false;
}
else{
myCamera.SetActive(false);
GetComponent<Drivetrain>().enabled = false;
GetComponent<CarController>().enabled = false;
GetComponent<Rigidbody>().useGravity = false;
}
}
void OnPhotonSerializeView(PhotonStream Stream, Photon$$anonymous$$essageInfo info){
if(stream.isWriting){
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else{
transform.position = (Vector3)Stream.RecieveNext();
transform.rotation = (Quaternion)Stream.RecieveNext();
}
}
}
Here they are:
Assets/Photon Unity Networking/$$anonymous$$ultiplayer.cs(24,28): error CS0103: The name
stream' does not exist in the current context 2. Assets/Photon Unity Networking/$$anonymous$$ultiplayer.cs(25,33): error CS0103: The namestream' does not exist in the current contextAssets/Photon Unity Networking/$$anonymous$$ultiplayer.cs(26,33): error CS0103: The name
stream' does not exist in the current context 4. Assets/Photon Unity Networking/$$anonymous$$ultiplayer.cs(29,70): error CS1061: TypePhotonStream' does not contain a definition forRecieveNext' and no extension methodRecieveNext' of typePhotonStream' could be found (are you missing a using directive or an assembly reference?) 5. Assets/Photon Unity Networking/$$anonymous$$ultiplayer.cs(30,73): error CS1061: TypePhotonStream' does not contain a definition forRecieveNext' and no extension methodRecieveNext' of type `PhotonStream' could be found (are you missing a using directive or an assembly reference?)
Your answer
Follow this Question
Related Questions
Character Selection Screen for Multiplayer - C# 1 Answer
[UNET] PlayerPrefab successfully spawns on Server, but Clients only see their own playerPrefab. 0 Answers
[Networking]How to call a command function from a UI element(a button) 2 Answers
How to select a specific network player - photon unity networking 3 Answers
How to synchronize disable and enabling game objects over the network? 0 Answers