- Home /
Can we use unity4.6 UI Image to instantiate in multilayer environment ?
hi.. i have tried a lot unity image for 2D game but getting problem in serialization
Can we use unity 4.6 UI Image to instantiate in multilayer environment ? If possible then give me some hint or code..
Or we can only use 2d Component - sprite , to successfully spawn in photon multi player?
Thank you
Just use RPC commands to do anything you want on each instantiation. General discussion: http://answers.unity3d.com/answers/332136/view.html
You mention "photon", just don't use it
Finally: there is very little reason to use Unity4 today. You must change to Unity5. You're truly wasting your time with Unity4.
Answer by ajaybhojani · Dec 19, 2015 at 09:03 AM
Thanks for answer. I did using RPC but not succeed. Image as prefab is instantiating using PUN, But does not displaying in screen , means I cant set position and scale of UI Image in sprite. Here is my code.
void StartSpawnProcess (float respawntime) { StartCoroutine ("SpawnPlayer", respawntime);
}
IEnumerator SpawnPlayer (float respawntime)
{
yield return new WaitForSeconds (respawntime);
Debug.Log (Spanpoints);
int index = Random.Range (0, Spanpoints.Length);
player = PhotonNetwork.Instantiate ("toprightplayer", Spanpoints [index].position,Spanpoints[index].rotation,0);
player.transform.SetParent(GameObject.Find("Panel").transform);
player.transform.GetComponent<RectTransform> ().anchorMax = new Vector3 (Spanpoints [index].anchorMax.x,Spanpoints [index].anchorMax.y);
player.transform.GetComponent<RectTransform> ().anchorMin = new Vector3 (Spanpoints [index].anchorMin.x,Spanpoints [index].anchorMin.y);
player.transform.GetComponent<RectTransform> ().offsetMax = new Vector3 (Spanpoints [index].offsetMax.x, Spanpoints [index].offsetMax.y);
player.transform.GetComponent<RectTransform> ().offsetMin = new Vector3 (Spanpoints [index].offsetMin.x, Spanpoints [index].offsetMin.y);//
player.transform.GetComponent<RectTransform>().anchoredPosition = Spanpoints[index].anchoredPosition;
player.transform.GetComponent<RectTransform>().anchoredPosition3D = Spanpoints[index].anchoredPosition3D;
player.transform.GetComponent<RectTransform>().sizeDelta = Spanpoints[index].sizeDelta;
player.transform.GetComponent<RectTransform>().pivot = Spanpoints[index].pivot;
}
And also serialize like this :
void StartSpawnProcess (float respawntime) { StartCoroutine ("SpawnPlayer", respawntime);
}
IEnumerator SpawnPlayer (float respawntime)
{
yield return new WaitForSeconds (respawntime);
Debug.Log (Spanpoints);
int index = Random.Range (0, Spanpoints.Length);
player = PhotonNetwork.Instantiate ("toprightplayer", Spanpoints [index].position,Spanpoints[index].rotation,0);
player.transform.SetParent(GameObject.Find("Panel").transform);
player.transform.GetComponent<RectTransform> ().anchorMax = new Vector3 (Spanpoints [index].anchorMax.x,Spanpoints [index].anchorMax.y);
player.transform.GetComponent<RectTransform> ().anchorMin = new Vector3 (Spanpoints [index].anchorMin.x,Spanpoints [index].anchorMin.y);
player.transform.GetComponent<RectTransform> ().offsetMax = new Vector3 (Spanpoints [index].offsetMax.x, Spanpoints [index].offsetMax.y);
player.transform.GetComponent<RectTransform> ().offsetMin = new Vector3 (Spanpoints [index].offsetMin.x, Spanpoints [index].offsetMin.y);//
player.transform.GetComponent<RectTransform>().anchoredPosition = Spanpoints[index].anchoredPosition;
player.transform.GetComponent<RectTransform>().anchoredPosition3D = Spanpoints[index].anchoredPosition3D;
player.transform.GetComponent<RectTransform>().sizeDelta = Spanpoints[index].sizeDelta;
player.transform.GetComponent<RectTransform>().pivot = Spanpoints[index].pivot;
}
Please tell me where i have put wrong code..
Your answer
Follow this Question
Related Questions
How do I change the import settings when using sprite.create with a WWW.texture from a png image. 1 Answer
How do importing image when game is running (Run Time) ???? 0 Answers
Is it possible to default sprites to Point (No filter) instead of Bilinear? 0 Answers
UI Image has no sprite definition 0 Answers
2D game using sprites. 1 Answer