手动摆放线段和标识太累,写个脚本做。如有问题,请加公众号 :哎呦还不错喔
void Start() { Vector3 Tpos = transform.position; int w , h ; w = Camera.main.WorldToScreenPoint(Tpos).x < Screen.width / 2 ? -1 : 1; h = Camera.main.WorldToScreenPoint(Tpos).y < Screen.height / 2 ? -1 : 1; GameObject xian = new GameObject(); LineRenderer Line = xian.AddComponent<LineRenderer>(); Line.SetWidth(0.1f, 0.1f); Line.SetVertexCount(3); Line.SetPosition(0, Tpos); Line.SetPosition(1, Tpos + new Vector3(2*w, 2*h, 0)); Line.SetPosition(2, Tpos + new Vector3(3*w, 2*h, 0)); Transform tr = (Instantiate(GameObject.Find("Button")) as GameObject).transform; tr.parent = GameObject.Find("Canvas").transform; tr.position = Tpos + new Vector3((3+0.5f)*w, 2*h, 0); tr.GetComponentInChildren<Text>().text=transform.name; }
时间: 2024-10-24 16:01:32