示例#1
0
 private void Update()
 {
     if (isGuiding)      // If it is guiding, adjust its position, rotation and scale based on dummy's position
     {
         Vector3    newPosition = (DMS.GetSelectedDummy().transform.position - anchorPoint) / positionOffset + anchorPoint;
         Quaternion newRotation = Quaternion.FromToRotation(Vector3.up, (DMS.GetSelectedDummy().transform.position - anchorPoint));
         float      newLength   = Vector3.Magnitude(DMS.GetSelectedDummy().transform.position - anchorPoint) * lengthOffset;
         transform.position   = newPosition;
         transform.rotation   = newRotation;
         transform.localScale = V3E.SetY(transform.localScale, newLength);
     }
 }
示例#2
0
    private Dictionary <SE.Flavor, GameObject> ticTacPrefabDict; // Dictionary of tic tac prefabs, with their types as keys


    /* Takes in an tic tac flavor and a spawn amount, and spawns that many tic tacs of that flavor. Will only spawn up to the
     * far path limit. */
    public void SpawnEnemies(SE.Flavor flavor, int spawnAmount)
    {
        if (!ticTacPrefabDict.ContainsKey(flavor))
        {
            Debug.LogWarning("Tic Tac with flavor " + flavor + " doesn't exist."); return;
        }

        SE.PathRoute pathRoute = ticTacPrefabDict[flavor].GetComponent <TicTac>().PathRoute;
        Path         path      = (pathRoute == SE.PathRoute.Melee) ? meleePath : rangedPath;

        for (int i = 0; i < spawnAmount && pathLimits[2] - path.scriptDict.Count > 0; i++)
        {
            Vector3 spawnPosition = spawnPositions.Dequeue();                                 // Get spawn position
            float   heightOffset  = ticTacPrefabDict[flavor].transform.GetChild(0).localScale.y +
                                    (transform.position.y - (transform.localScale.y / 2.0f)); // Used to spawn object above field
            spawnPosition = V3E.SetY(spawnPosition, heightOffset);
            spawnPositions.Enqueue(spawnPosition);

            GameObject ticTac       = Instantiate(ticTacPrefabDict[flavor], spawnPosition, Quaternion.identity); // Instantiate
            TicTac     ticTacScript = ticTac.GetComponent <TicTac>();
            ticTacScript.InitializeVariables(gameObject, collector);

            float delayTime = delayTimes.Dequeue();  // Get delay time
            delayTimes.Enqueue(delayTime);

            if (path.scriptDict.Count < pathLimits[0])   // Set path distance and start moving towards a new path position
            {
                ticTacScript.CurrPathDistance = SE.PathDistance.Close;
                ticTacScript.StartAdvanceCoroutine(((Random.insideUnitSphere * path.radii[0]) + path.centers[0]), delayTime);
                path.scriptDict.Add(ticTac.GetInstanceID(), ticTacScript);
            }
            else if (path.scriptDict.Count < pathLimits[1])
            {
                ticTacScript.CurrPathDistance = SE.PathDistance.Mid;
                ticTacScript.StartAdvanceCoroutine(((Random.insideUnitSphere * path.radii[1]) + path.centers[1]), delayTime);
                path.scriptDict.Add(ticTac.GetInstanceID(), ticTacScript);
            }
            else                // farPathLimit
            {
                ticTacScript.CurrPathDistance = SE.PathDistance.Far;
                ticTacScript.StartAdvanceCoroutine(((Random.insideUnitSphere * path.radii[2]) + path.centers[2]), delayTime);
                path.scriptDict.Add(ticTac.GetInstanceID(), ticTacScript);
            }
        }
    }
示例#3
0
 private void OnTriggerEnter(Collider other)
 {
     if (!triggered)
     {
         Vector3 hitPosition = V3E.SetY(transform.position, other.transform.position.y); // So explosion starts from inside the field rather
                                                                                         // than at the orb's height
         Collider[] hitColliders = Physics.OverlapSphere(hitPosition, transform.localScale.x / 2.0f, 1 << LayerMask.NameToLayer("TicTac"));
         foreach (Collider hitCollider in hitColliders)
         {
             Destroy(hitCollider.GetComponent <Animator>());
             Rigidbody hitRigidbody = hitCollider.GetComponent <Rigidbody>();
             hitRigidbody.isKinematic = false;
             hitRigidbody.useGravity  = true;
             hitRigidbody.AddExplosionForce(explosionForce, hitPosition, transform.localScale.x / 2.0f, upwardsModifier);
             hitTicTacs.Add(hitRigidbody.transform.parent.gameObject);
         }
         StartCoroutine(RemoveTicTacs());
         triggered = true;
     }
 }
示例#4
0
    /* Takes in a path position and delay time and moves towards that path position. Waits a delay time amount of
     * seconds and then begins attacking once the path position has been reached. */
    private IEnumerator Advance(Vector3 pathPosition, float delayTime)
    {
        yield return(new WaitForSeconds(delayTime));

        animator.SetTrigger("AdvanceTrigger");

        pathPosition = V3E.SetY(pathPosition, transform.position.y);    // Set height of path position to tic tac's height
        while (Vector3.Distance(transform.position, pathPosition) > minArrivalDistance)
        {
            float step = Speed * Time.deltaTime;
            transform.position = Vector3.MoveTowards(transform.position, pathPosition, step);
            yield return(null);
        }
        transform.LookAt(V3E.SetY(collectorScript.transform.position, transform.position.y));
        if (CurrPathDistance == SE.PathDistance.Close)
        {
            animator.SetTrigger("AttackTrigger");
        }
        else
        {
            animator.SetTrigger("IdleTrigger");
        }
    }