// Use this for initialization protected override void Start() { transform.localScale = Vector3.zero; pathfinder = GetComponent <scrPathfinder>(); pathfinder.Target = scrAICore.Instance.gameObject; pathfinder.Resume(); link = GetComponent <LineRenderer>(); base.Start(); }
// Update is called once per frame protected override void Update() { if (Expired) { // Destroy segments. if (ExplosionPrefab != null) { for (int i = 0; i < Segments.Length; ++i) { GameObject explosion = (GameObject)Instantiate(ExplosionPrefab, Segments[i].transform.position, Quaternion.identity); explosion.particleSystem.startColor = Color.Lerp(Segments[i].renderer.material.color, Color.white, 0.5f); Destroy(Segments[i].gameObject); } } // NOW destroy self. Destroy(gameObject); return; } if (Vector2.Distance(transform.position, scrPlayer.Instance.transform.position) < 50 && !Physics.Linecast(transform.position, scrPlayer.Instance.transform.position, 1 << LayerMask.NameToLayer("Node"))) { pathfinder.Pause(); Vector3 direction = Vector3.Lerp((transform.position - (Vector3)prevPositions[0]).normalized, (scrPlayer.Instance.transform.position - transform.position).normalized, 0.3f).normalized *Time.deltaTime *Speed; transform.position += direction; fireTimer += Time.deltaTime * fireRate; if (fireTimer >= 1) { fireTimer = 0; scrEnemyMaster.BulletPool.Create(new BulletPowerup(scrNodeMaster.ColCoreInfected, 80, 1, 0, 0, 0, false, false), transform.position, direction.normalized, false, true); audio.PlayOneShot(FireSound); } } else { pathfinder.Resume(); } // Shift segments scaled by the velocity, which is worked out by the translation of the head since the last update. Deltatime is not needed because the translation is already dependant on it.. spacingTimer += 0.05f * Vector2.Distance((Vector2)transform.position, prevHeadPosition); prevHeadPosition = transform.position; if (spacingTimer >= spacingDelay) { spacingTimer = 0; prevPositions[0] = nextPositions[0]; nextPositions[0] = transform.position; for (int i = 1; i < Segments.Length; ++i) { prevPositions[i] = nextPositions[i]; nextPositions[i] = prevPositions[i - 1]; } } bool allExpired = true; for (int i = 0; i < Segments.Length; ++i) { if (Segments[i] == null) { continue; } // If the segment has expired, disable its enemy script, hide its children and show its "dead" skeleton child. if (Segments[i].Expired) { if (Segments[i].enabled) { Segments[i].renderer.material.color = Color.black; Segments[i].transform.localScale *= 0.5f; Segments[i].collider2D.enabled = false; Segments[i].enabled = false; Segments[i].GetComponentInChildren <TextMesh>().text = ""; } } else { allExpired = false; } Vector2 direction = nextPositions[i] - prevPositions[i]; Segments[i].transform.rotation = Quaternion.RotateTowards(Segments[i].transform.rotation, Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x)), 180 * Time.deltaTime); Segments[i].transform.position = Vector2.Lerp(prevPositions[i], nextPositions[i], spacingTimer / spacingDelay); } // If all segments are gone, destroy self. if (allExpired) { damageTimer = DamageToDestroy; } base.Update(); }
// Update is called once per frame protected override void Update() { if (transform.localScale.x == 0.0f) { return; } if (startAngle != 0.0f || Vector3.Distance(transform.position, pathfinder.Target.transform.position) <= 50.0f) { // Initialisation of orbit. if (startAngle == 0.0f) { Vector3 direction = pathfinder.Target.transform.position - transform.position; startAngle = Mathf.Atan2(-direction.y, direction.x) - Mathf.PI * 0.5f; } pathfinder.Pause(); transform.position = pathfinder.Target.transform.position + new Vector3(50.0f * Mathf.Sin(startAngle + orbitTimer * Mathf.PI * 2), 50.0f * Mathf.Cos(startAngle + orbitTimer * Mathf.PI * 2), 0.0f); orbitTimer += Time.deltaTime * rotateSpeed * 0.001f; if (ChildCore.transform.localScale.x > 0.0f) { ChildCore.transform.localScale = Vector3.one * (ChildCore.transform.localScale.x - Time.deltaTime / transform.localScale.x * 0.05f); scrAICore.Instance.Learn(true, Time.deltaTime / transform.localScale.x); if (ChildCore.transform.localScale.x <= 0.0f) { ChildCore.transform.localScale = Vector3.zero; link.SetVertexCount(0); } else { // Create a curved link like the nodes. float curve = 20.0f; Vector3 control = Vector3.Lerp(transform.position, pathfinder.Target.transform.position, 0.5f) - curve * Vector3.back; for (int i = 0; i < 5; ++i) { float t = (float)i / (5 - 1); float tInv = 1.0f - t; link.SetPosition(i, tInv * tInv * transform.position + 2 * tInv * t * control + t * t * pathfinder.Target.transform.position); } link.SetColors(Color.Lerp(Color.clear, Color.red, Mathf.Abs(orbitTimer) / 0.05f), Color.Lerp(Color.clear, Color.red, Mathf.Abs(orbitTimer) / 0.2f)); } } } else { pathfinder.Resume(); } // Rotate the shell. ChildShell.transform.Rotate(0.0f, rotateSpeed * Time.deltaTime, 0.0f); if (Vector2.Distance(transform.position, scrPlayer.Instance.transform.position) < 70) { fireTimer += Time.deltaTime * fireRate; if (fireTimer > 1.0f) { fireTimer = 0.0f; Vector3 position = ChildShell.transform.TransformPoint(0.5f * new Vector3(Mathf.Sin(fireCannon / 8.0f * Mathf.PI * 2), 0.0f, Mathf.Cos(fireCannon / 8.0f * Mathf.PI * 2))); scrEnemyMaster.BulletPool.Create(new BulletPowerup(Color.red, 40.0f, 10.0f * transform.localScale.x, 0, 0, 0, false, true), position, (position - transform.position).normalized, false, true); ++fireCannon; if (fireCannon == 8) { fireCannon = 0; } } } base.Update(); }
// Update is called once per frame protected override void Update() { if (damageTimer >= DamageToDestroy) { scrPlayer.Instance.Powerups.Enqueue(powerup); scrGUI.Instance.EnqueuePowerup(Name, powerup.Colour); } pathfinder.Resume(); // If sieging, shoot at the node. if (SiegeNode != null && SiegeNode.Cubes != null) { if (!SiegeNode.gameObject.activeSelf || SiegeNode.Infected) { SiegeNode = null; pathfinder.Target = scrPlayer.Instance.gameObject; base.Update(); return; } if (targetCubeIndex >= SiegeNode.Cubes.Length) { targetCubeIndex = 0; } // Change cube if target cube is destroyed. if (SiegeNode.Cubes[targetCubeIndex] == null) { ++targetCubeIndex; } else { Vector2 direction = SiegeNode.Cubes[targetCubeIndex].Value.transform.position - transform.position; transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x)), 180 * Time.deltaTime); // Check the distance. if (direction.magnitude < scrNodeMaster.CELL_SIZE) { fireTimer += Time.deltaTime * fireRate; if (fireTimer >= 1) { fireTimer = 0; StartCoroutine(Shoot(Random.Range(3, 8))); } } } } // If not sieging, check for a node to siege. else { // Aim towards the player. Vector2 direction = scrPlayer.Instance.transform.position - transform.position; transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x)), 180 * Time.deltaTime); if (direction.magnitude < scrNodeMaster.CELL_SIZE) { fireTimer += Time.deltaTime * fireRate; if (fireTimer >= 1) { fireTimer = 0; StartCoroutine(Shoot(Random.Range(3, 8))); } } // Get nodes that are close by. Collider2D[] nearNodes = Physics2D.OverlapCircleAll(transform.position, scrNodeMaster.CELL_SIZE, 1 << LayerMask.NameToLayer("Node")); // Get a near node that is clean. scrNode clean = null; foreach (Collider2D c in nearNodes) { scrNode n = c.GetComponent <scrNode>(); if (!n.Infected && !n.Blocked) { clean = n; break; } } // If the clean node was set, start sieging. if (clean != null) { SiegeNode = clean; pathfinder.Target = SiegeNode.gameObject; } } base.Update(); }
public void Upload() { Uploading = true; Parent = null; pathfinder.Resume(); }