// Use this for initialization void Start() { WiggleLogic = SkilledTankWiggleLogic; initSegmentNum = segmentNum; gameObject.layer = LayerMask.NameToLayer("Beak" + playerNum); transform.GetChild(0).gameObject.layer = LayerMask.NameToLayer("Beak" + playerNum); mouth = transform.GetChild(0); moveSpeed = defaultMoveSpeed; rotSpeed = defaultRotSpeed; defaultScale = transform.localScale.x; SetupBody(segmentNum); GetComponent <Renderer>().material.SetFloat("_OverlayAlpha", 0.0f); moveHighlightSprite = WadeUtils.Instantiate(moveHighlightObj).GetComponent <SpriteRenderer>(); moveHighlightSprite.color = new Color(0f, 0f, 0f, 0f); moveHighlightSprite.transform.parent = transform; moveHighlightSprite.transform.localPosition = Vector3.zero; carryHighlightSprite = WadeUtils.Instantiate(carryHighlightObj).GetComponent <SpriteRenderer>(); carryHighlightSprite.color = new Color(1f, 0f, 0f, 0f); carryHighlightSprite.transform.parent = segments[5]; carryHighlightSprite.transform.localPosition = Vector3.zero; initCarryHighlightScale = carryHighlightSprite.transform.localScale.x; }
void SetupBody() { for (int i = 0; i < segmentNum; i++) { GameObject segment = WadeUtils.Instantiate(segmentPrefab, trans.position - trans.up * (i + 1) * circleDist, segmentPrefab.transform.rotation); segment.name = "Segment" + i; segment.transform.parent = segmentHolder; segment.layer = segmentHolder.gameObject.layer; segments[i] = segment.transform; DistanceJoint2D segJoint = segment.GetComponent <DistanceJoint2D>(); segJoint.connectedBody = (i == 0) ? rigidbody2D : segments[i - 1].rigidbody2D; segJoint.collideConnected = false; segJoint.distance *= circleDist; if (i == segmentNum - 1) { TrailRenderer tr = segment.AddComponent <TrailRenderer>(); tr.startWidth = 0.3f; tr.endWidth = 0.1f; tr.material = GetComponent <MeshRenderer>().material; segment.rigidbody2D.isKinematic = true; } } }
void UpdateText() { if (text != prevText) { for (int i = 0; i < letterObjs.Length; i++) { if (letterObjs[i]) { Destroy(letterObjs[i]); } } letterObjs = new GameObject[text.Length]; for (int i = 0; i < text.Length; i++) { if (text[i] != ' ') { GameObject letterObj = WadeUtils.Instantiate(letterPrefab); Text letterText = letterObj.GetComponent <Text>(); letterText.rectTransform.SetParent(transform); letterText.rectTransform.localScale = Vector3.one; letterText.text = text[i].ToString(); letterObjs[i] = letterObj; } } prevText = text; } }
void OnTriggerEnter2D(Collider2D col) { Tail tail = col.GetComponent <Tail>(); if (tail) { if (tail.worm == this) { if (!carrying) { Vector3 checkPos = Vector3.zero; for (int i = 0; i < segments.Length; i++) { checkPos += segments[i].position; } checkPos *= 1.0f / (segments.Length); GameObject catchCheckObj = WadeUtils.Instantiate(catchCheckPrefab, checkPos, transform.rotation); catchCheckObj.GetComponent <CatchCheck>().worm = this; } } else { if (tail.worm.carrying) { tail.worm.Puke(true); } } } }
void GameSetup() { gameObj.SetActive(true); team1Color = colorOptions[characterSelect.teamColorIndices[0]]; team2Color = colorOptions[characterSelect.teamColorIndices[1]]; ScoreManager sm = ScoreManager.instance; sm.team1TimeText.ToList().ForEach(text => text.color = team1Color); sm.team2TimeText.ToList().ForEach(text => text.color = team2Color); sm.ResetScore(); sm.ResetTimer(); int timerColor = characterSelect.teamColorIndices[0] + characterSelect.teamColorIndices[1]; // This is a hack lol if (characterSelect.teamColorIndices[0] > 2 && characterSelect.teamColorIndices[1] > 2) { timerColor += 6; } else if (characterSelect.teamColorIndices[0] > 1 && characterSelect.teamColorIndices[1] > 1) { timerColor += 5; } else if (characterSelect.teamColorIndices[0] > 0 && characterSelect.teamColorIndices[1] > 0) { timerColor += 3; } sm.SetTimerColor(complimentaryColors[timerColor - 1]); DestroyAllBalls(); if (characterSelect.GetPlayerInfos().Length > 4) { WadeUtils.Instantiate(ballPrefab, Vector3.zero + Vector3.up * multiBallSpawnOffset, Quaternion.identity); WadeUtils.Instantiate(ballPrefab, Vector3.zero - Vector3.up * multiBallSpawnOffset, Quaternion.identity); } else { WadeUtils.Instantiate(ballPrefab); } SpawnPlayers(); // Spawn players // Fade in game music }
GameObject CreateSegment(Vector3 spawnPos) { GameObject segment = WadeUtils.Instantiate(segmentPrefab, spawnPos, segmentPrefab.transform.rotation); segment.transform.SetParent(segmentHolder); SpringJoint2D segJoint = segment.GetComponent <SpringJoint2D>(); segJoint.enableCollision = false; segJoint.frequency = 0.0f; segJoint.distance *= circleDist; return(segment); }
public Worm CreateWorm(Vector3 pos, bool lookUp, int playerNum, int teamNum, Color color, Texture2D tex) { Quaternion spawnRot = lookUp ? Quaternion.identity : Quaternion.Euler(0.0f, 0.0f, 180.0f); GameObject wormObj = WadeUtils.Instantiate(wormPrefab, pos, spawnRot); worms.Add(wormObj); Worm worm = wormObj.GetComponentInChildren <Worm>(); worm.playerNum = playerNum; worm.teamNum = teamNum; worm.GetComponent <Renderer>().material.SetTexture("_MainTex", tex); worm.GetComponent <Renderer>().material.SetColor("_MainTint", color); return(worm); }
void CreateAdviceText() { GameObject newAdviceText = WadeUtils.Instantiate(adviceTextPrefab); newAdviceText.transform.SetParent(transform); newAdviceText.transform.localScale = Vector3.one; newAdviceText.GetComponent <RectTransform>().localPosition = Vector3.right * spawnDistance; int randNum = Random.Range(0, noRepeatAdviceText.Count - 1); newAdviceText.GetComponent <Text>().text = noRepeatAdviceText[randNum]; noRepeatAdviceText.Remove(noRepeatAdviceText[randNum]); if (noRepeatAdviceText.Count < 1) { noRepeatAdviceText = adviceTexts.ToList(); } activeAdviceTexts.Add(newAdviceText.GetComponent <Text>()); }
void SetupCornerColliders() { Vector3 topLeft = worldMax; topLeft.x *= -1; Vector3 bottomRight = worldMin; bottomRight.x *= -1; GameObject topLeftCol = WadeUtils.Instantiate(cornerColPrefab, topLeft + (Vector3.right - Vector3.up) * 2.0f, Quaternion.identity); topLeftCol.name = "TopLeftCorner"; topLeftCol.transform.SetParent(transform); GameObject topRightCol = WadeUtils.Instantiate(cornerColPrefab, worldMax + (-Vector3.right - Vector3.up) * 2.0f, Quaternion.Euler(0.0f, 0.0f, 270.0f)); topRightCol.name = "TopRightCorner"; topRightCol.transform.SetParent(transform); GameObject bottomRightCol = WadeUtils.Instantiate(cornerColPrefab, bottomRight + (-Vector3.right + Vector3.up) * 2.0f, Quaternion.Euler(0.0f, 0.0f, 180.0f)); bottomRightCol.name = "BottomRightCorner"; bottomRightCol.transform.SetParent(transform); GameObject bottomLeftCol = WadeUtils.Instantiate(cornerColPrefab, worldMin + (Vector3.right + Vector3.up) * 2.0f, Quaternion.Euler(0.0f, 0.0f, 90.0f)); bottomLeftCol.name = "BottomLeftCorner"; bottomLeftCol.transform.SetParent(transform); }
public GameObject ResetBall() { DestroyAllBalls(); return(WadeUtils.Instantiate(ballPrefab)); }
IEnumerator PukeEffects(bool spawnBall) { isPuking = true; pukeTimer = 0.0f; bool ballSpawned = !spawnBall; Vector3 initMouthScale = mouth.localScale; GameObject pukeEffectObj = WadeUtils.Instantiate(pukeEffectPrefab, transform.position, transform.rotation); mouth.GetComponent <SpriteRenderer>().sprite = openSprite; GetComponent <Rigidbody2D>().velocity = Vector3.zero; for (int i = 0; i < segments.Length; i++) { segments[i].GetComponent <Rigidbody2D>().velocity = Vector3.zero; } while (pukeTimer < pukeTime) { if (pukeEffectObj) { pukeEffectObj.transform.position = mouth.position; pukeEffectObj.transform.rotation = transform.rotation; pukeEffectObj.transform.localRotation *= Quaternion.Euler(-90.0f, 0.0f, 0.0f); } if (pukeTimer > pukeTimer / 10.0f) { mouth.localScale = new Vector3(1.0f + Mathf.Cos(pukeTimer * 20.0f) / 2.0f, mouth.localScale.y, mouth.localScale.z); } if (pukeTimer > pukeTimer / 3.0f) { if (!ballSpawned) { GameObject ballObj = WadeUtils.Instantiate(ballPrefab, transform.position + transform.up, transform.rotation); ballObj.layer = LayerMask.NameToLayer("IgnorePlayer"); ballObj.GetComponent <Rigidbody2D>().AddForce(transform.up * pukeForce * 100); ballObj.GetComponent <Rigidbody2D>().AddTorque(pukeForce * 0.01f); Ball ball = ballObj.GetComponent <Ball>(); ball.StartCoroutine(ball.ScaleUp(0.0f)); ballSpawned = true; } else { GetComponent <Rigidbody2D>().AddForce(-transform.up * pukeForce * (1.0f - pukeTimer / pukeTime)); for (int i = 0; i < segments.Length; i++) { segments[i].GetComponent <Rigidbody2D>().AddForce(-transform.up * pukeForce * (1.0f - pukeTimer / pukeTime)); } } } if (pukeTimer > pukeTime * 0.5f) { if (pukeEffectObj) { pukeEffectObj.GetComponent <ParticleSystem>().enableEmission = false; } } else { GetComponent <Rigidbody2D>().AddForce(-transform.up * pukeForce); } pukeTimer += Time.deltaTime; yield return(0); } pukeTimer = 0.0f; mouth.GetComponent <SpriteRenderer>().sprite = closedSprite; while (Vector3.Distance(mouth.localScale, Vector3.one) > 0.05f) { mouth.localScale = Vector3.Lerp(mouth.localScale, Vector3.one, Time.deltaTime); yield return(0); } Destroy(pukeEffectObj); mouth.localScale = initMouthScale; isPuking = false; }