private Transform createSomething(Transform trans, int x, int y, string name, bool isPlayers = true) { posStruct realPos = calculatePos(x, y); Transform something = Instantiate(trans, transform.position, transform.rotation); if (isPlayers) { something.parent = transform; } else { something.parent = transform.parent; } something.localPosition = new Vector3(realPos.x, realPos.y, 0); if (name != "") { something.name = name; } return(something); }
void snakeMove(int forward) { if (isDead) { return; } AudioManager.Instance.PlaySound(3); if (!readyAdd) { Transform temp_Head; Transform temp_Tail; Transform temp_TailSecond; Transform temp_TailThird; temp_Head = transform.Find("Head"); temp_Tail = transformQueue.Dequeue(); temp_TailSecond = transformQueue.Peek(); temp_TailThird = transformQueue.Peek(); temp_Tail.localPosition = new Vector3(temp_Head.localPosition.x + fourForward[forward, 0], temp_Head.localPosition.y + fourForward[forward, 1], 0); temp_Tail.name = "Head"; if (isLocalPlayer) { temp_Tail.GetComponent <RawImage>().color = m_colorBlue; } else { temp_Tail.GetComponent <RawImage>().color = m_colorBlack; } temp_TailSecond.name = "Tail"; temp_TailSecond.GetComponent <RawImage>().color = m_colorGrey; temp_TailThird.name = "TailSecond"; if (bodyLength == 3) { temp_Head.name = "TailSecond"; } else { temp_Head.name = "Body"; } temp_Head.GetComponent <RawImage>().color = m_colorLessBlack; transformQueue.Enqueue(temp_Tail); } else { Transform temp_Head; Transform temp_Head_New; temp_Head = transform.Find("Head"); posStruct pos_easy = calculateEasyPos(temp_Head.localPosition.x + fourForward[forward, 0], temp_Head.localPosition.y + fourForward[forward, 1]); temp_Head_New = createSomething(headTransform, pos_easy.x, pos_easy.y, "Head"); transformQueue.Enqueue(temp_Head_New); temp_Head.name = "Body"; temp_Head.GetComponent <RawImage>().color = m_colorLessBlack; bodyLength++; readyAdd = false; } }