Beispiel #1
0
    public void LaunchMinion(Vector3 toWhere)
    {
        if (minionList.Count <= 0 || rebuildCoroutine != null || toWhere == Vector3.zero)
        {
            return;
        }

        foreach (Transform child in minionList)
        {
            //Launch the minion
            child.GetComponent <Rigidbody2D>().velocity = (toWhere - child.position).normalized * minionSpeed;

            OrbitAroundObject orbitScript = child.GetComponent <OrbitAroundObject>();
            if (orbitScript != null)
            {
                orbitScript.enabled = false;    //Stop it from orbiting around
            }

            //Put it directly into object master's list
            child.parent = null;
            objectMasterScript.AddChild(child);
        }

        minionList.Clear();
    }
Beispiel #2
0
    public IEnumerator RebuildMinionList(int numOfChild)
    {
        if (numOfChild <= 0 || minionList.Count > 0)
        {
            yield break;
        }

        for (int indx = minionList.Count - 1; indx >= 0; indx--)
        {
            if (minionList[indx] == null)
            {
                minionList.RemoveAt(indx);
            }
        }

        for (int indx = 0; indx < numOfChild; indx++)
        {
            int       randomIndx = Random.Range(0, backupList.Count);
            Transform child      = backupList[randomIndx];

            float randomRad   = Random.Range(innerRadius, outerRadius);
            float randomAngle = Random.Range(0.0f, Mathf.PI);

            //Calculate x and y from radius and angle
            Vector3 spawnPos = new Vector3(randomRad * Mathf.Cos(randomAngle),
                                           randomRad * Mathf.Sin(randomAngle),
                                           0);
            //Debug.Log(randomRad + "   " + randomAngle + "    " + Vector3.Distance(spawnPos, transform.position) + "     " + randomRad * Mathf.Cos(randomAngle) + "    " + randomRad * Mathf.Sin(randomAngle));

            spawnPos += transform.position;

            //Rebuild the minions randomly
            Transform newObject = Instantiate(child, spawnPos, Quaternion.identity);

            //Delay the start
            OrbitAroundObject orbitScript = newObject.GetComponent <OrbitAroundObject>();
            if (orbitScript != null)
            {
                orbitScript.startDelay = scaleTime * 2;
            }

            //Scale with animation
            Vector3 initialScale = child.localScale;
            newObject.DOScale(Vector3.zero, 0.0001f);
            newObject.DOScale(initialScale, scaleTime).SetEase(Ease.OutElastic);

            newObject.gameObject.SetActive(true);

            //Set parent
            newObject.parent = spriteHolder;
            minionList.Add(newObject);
            yield return(new WaitForSeconds(rebuildWait));
        }
        rebuildCoroutine = null;
    }