private void FollowTarget() { Vector3 direction = target.position - myTransform.position; myTransform.position += direction.normalized * speed * Time.deltaTime; if (direction.sqrMagnitude < shootDistance) { state = SputnikCrossState.Focus; } }
public void Activate() { myTransform = transform; target = FindObjectOfType <PlayerController>().transform; state = SputnikCrossState.Activating; size = myTransform.localScale.x; myTransform.localScale = activateStartSize * Vector3.one; laser = myTransform.GetComponentInChildren <SputnikLaser>(); laser.Activate(); gameObject.SetActive(true); shootDistance *= shootDistance; }
private void Focus() { if (myTransform.localScale.x >= focusSize) { myTransform.localScale -= focusSpeed * Vector3.one * Time.deltaTime; if ((myTransform.position - target.position).sqrMagnitude > avgDifference) { state = SputnikCrossState.Activating; } } else { if ((myTransform.position - target.position).sqrMagnitude <= avgDifference) { Attack(); state = SputnikCrossState.Activating; } } }
void Update() { if (state == SputnikCrossState.Activating) { if (myTransform.localScale.x < size) { myTransform.localScale += activateSpeed * Vector3.one * Time.deltaTime; } else { state = SputnikCrossState.Follow; } } else if (state == SputnikCrossState.Follow) { FollowTarget(); } else if (state == SputnikCrossState.Focus) { Focus(); } }