- Home /
Question by
Wakeful · Dec 14, 2014 at 08:52 AM ·
c#networkingconvertnetworkviewnetworkviewid
Convert Network.ViewID to Int
Exactly what the title says. How do you do this in c#? I want to be able to get the viewID and get a int of it.
int shotShellID = shotShell.GetComponent<NetworkView>().viewID;
It keeps giving me an error:
Assets/Scripts/TankController.cs(69,17): error CS0029: Cannot implicitly convert type `UnityEngine.NetworkViewID' to `int'
Thanks for your help! ~Wakeful
Comment
Best Answer
Answer by NaBUru38 · Sep 09, 2015 at 01:57 PM
gameObject.GetComponent <NetworkView>().viewID.ToString()
returns "AllocatedID: 1234" (or another number)
So,
gameObject.GetComponent <NetworkView>().viewID.ToString().Substring (13);
returns "1234" (or the respective number)
So,
Convert.ToInt32 (gameObject.GetComponent <NetworkView>().viewID.ToString().Substring (13);)
returns 1234 (or the respective number) as an integer.